【问题标题】:wordpress query_post trouble [duplicate]wordpress query_post麻烦[重复]
【发布时间】:2013-10-08 22:27:41
【问题描述】:

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

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

【问题讨论】:

  • 您好,请务必先使用 Google!对wordpress query_posts multiple categories 的查询应该会为您提供所需的所有指针。谢谢!

标签: php wordpress categories


【解决方案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';
}

【讨论】:

    猜你喜欢
    • 2023-03-09
    • 1970-01-01
    • 2017-01-11
    • 1970-01-01
    • 2013-04-27
    • 2012-09-13
    • 2013-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多