-1

如何将此查询扩展到多个类别而不仅仅是一个?甚至更好的方法是如何进行此查询以按 ID 而不是 slug 过滤类别?

query_posts( array( 'category' => 'games', 'posts_per_page' => -1 ) ); 
4

1 回答 1

1
query_posts(array('cat' => '1,2,3,4', 'posts_per_page' => -1));

但你应该WP_Query改用。

$args = array(
   'cat' => '1,2,3,5',
   'posts_per_page' => -1
);
$posts = new WP_Query($args):
//check if it has posts
if($posts->have_posts()){
    //loop through the post
    while($posts->have_posts()){
        $posts->the_post();
        echo the_title();
        echo the_content();
   }
}else{
    echo 'No posts found';
}
于 2013-10-08T22:31:48.487 回答