我所做的事情的逻辑似乎有问题。
我只想在自定义术语中显示最新的帖子。但我会显示该术语的所有帖子,即使我使用posts_per_page => 1
我有一个名为“双胞胎”和“双肖像”的分类法,我在一个名为“名人”的类别中有两篇帖子,都有“双肖像”这个词。我的代码输出在正确的类别中,但正如我所说的,它是为每个帖子输出的,而不仅仅是一个帖子。
下面是我使用的代码:
$post_type = \'post\';
$taxonomies = get_object_taxonomies( (object) array( \'post_type\' => $post_type ) );
foreach( $taxonomies as $taxonomy ) :
$terms = get_terms( $taxonomy );
foreach( $terms as $term ) :
$args = array(
\'tax_query\' => array(
array(
\'taxonomy\' => $taxonomy,
\'field\' => \'slug\',
\'terms\' => $term->slug
)
),
\'posts_per_page\' => 1,
\'ignore_sticky_posts\' => true,
\'orderby\' => \'modified\',
);
$posts = new WP_Query( $args );
if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post();
if(in_category($str)) {
if(has_term(\'double portrait\',\'twin\')) {
echo the_excerpt();
}
}
endwhile; endif;
endforeach;
endforeach;