如何在wordpress循环中显示一个类别或另一个类别的帖子?

问题描述

我正在尝试创建一个wordpress循环,该循环显示来自类别1或类别2的帖子。我目前只显示两个类别的帖子。我已经遍及整个互联网,但是找不到我想要的东西。

这是我循环的代码,当前仅显示分配给这两个类别的帖子。

     <?PHP 
// Example argument that defines three posts per page. 
$args = array( 
    'posts_per_page' => 3,'cat' => 1,'cat' => 154
); 
 
// Variable to call WP_Query. 
$the_query = new WP_Query( $args ); 
 
if ( $the_query->have_posts() ) : 
$i = 0;
    // Start the Loop 
    while ( $the_query->have_posts() ) : $the_query->the_post(); 
if ( $i == 0 ) :  ?>


//loop content here


<?PHP endif; 
    // End the Loop 
$i++;
    endwhile; 
else: 
// If no posts match this query,output this text. 
    _e( 'Sorry,no posts matched your criteria.','textdomain' ); 
endif; 
 
wp_reset_postdata(); 
?>

解决方法

您是否尝试在参数中使用category __?

    category__in => array(1,154)