0
我在我的wordpress博客中安装了Wp-Types插件。我创建了一个名为“演示”的自定义分类。我在其中添加了两个类别。如何在WordPress中使用自定义文本显示帖子?
- firstdemo
- seconddemo
现在我想告诉从这个自定义分类的职位,所以我用这个:
<?php
$custom_terms = get_terms('demo');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'demo',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo '<h2>'.$custom_term->name.'</h2>';
while($loop->have_posts()) : $loop->the_post();
echo '<a href="'.get_permalink().'">'.get_the_title().'</a>';
endwhile;
}
}
?>
但它显示谁正在使用分类的所有帖子。我想显示来自seconddemo的帖子。怎么做?
不知道你的'条件=> $ custom_term-> slug'是应该做的。 – Aibrean
它仍然没有工作......它显示相同的输出 –
删除Foreach循环条件并尝试它。 –