wordpress query_post麻烦

时间:2013-10-08 22:27:41

标签: php wordpress categories

如何将此查询扩展到多个类别而不只是一个?甚至更好的我如何使这个查询按ID而不是slug过滤类别?

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

1 个答案:

答案 0 :(得分: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';
}