【发布时间】:2015-10-15 15:26:15
【问题描述】:
我已经在我的 wordpress 博客中安装了 Wp-Types 插件。我创建了一个名为“演示”的自定义分类法。我在其中添加了两个类别。
- 第一个演示
- 第二个演示
现在我想显示来自这个自定义分类的帖子,所以我使用这个:
<?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 的帖子。怎么办?
【问题讨论】: