WP_Query()不返回所有条目

Ens*_*uki 30 php wordpress

我有这个查询只返回我在表上的一些条目.我有超过10个帖子但这个查询只返回6.请帮助提出建议

$query = new WP_Query("year=2011&monthnum=09&post_status=publish&post_type=post&orderby=post_date&order=DESC");
while ($query->have_posts()):
    $query->the_post();
    $title=get_the_Title();                                                                                                                  
    echo"<p><input type=\"checkbox\" name=\"MyArticle[]\" value=\"".get_the_ID()."\">".get_the_Title()."</p>";
endwhile;               
wp_reset_query();
Run Code Online (Sandbox Code Playgroud)

dre*_*010 91

尝试添加posts_per_page=-1传递给的参数字符串WP_Query.

如果未设置该值,则它将回退以使用您设置的每页默认帖子选项Settings >> Reading >> Blog pages show at most.

我的猜测是这个值是6所以它返回了很多帖子,因为你没有指定不同的限制.

  • 无论点击是否回答,这都是正确的答案.谢谢 (7认同)
  • **posts_per_page = -1**解决了问题.谢谢一堆 (2认同)

小智 15

$args = array(
    'post_type' => 'product',
    'orderby' => 'ASC',
    'posts_per_page'=>-1
);
$wp_query = new WP_Query($args);
Run Code Online (Sandbox Code Playgroud)