-1

このクエリを 1 つだけでなく複数のカテゴリに拡張するにはどうすればよいですか? または、スラッグの代わりに ID でカテゴリをフィルタリングするようにこのクエリを作成するにはどうすればよいですか?

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 に答える