php WP_Query() 不返回所有条目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12943236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WP_Query() does not return all entries
提问by Enstine Muki
I have this query that returns only a few of the entries I have on the table. I have over 10 posts but this query only returns 6. Please help with suggestions
我有这个查询,它只返回我在表中的几个条目。我有超过 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();
回答by drew010
Try adding posts_per_page=-1to the string of parameters passed to WP_Query.
尝试添加posts_per_page=-1到传递给WP_Query.
If that value is not set, then it falls back to use the default posts per page option you have set in Settings >> Reading >> Blog pages show at most.
如果未设置该值,则它会回退到使用您在 中设置的默认每页帖子选项Settings >> Reading >> Blog pages show at most。
My guess is that this value is 6 so its returning that many posts since you did not specify a different limit.
我的猜测是这个值是 6,所以它返回那么多帖子,因为你没有指定不同的限制。
回答by Vishal Sadarani
$args = array(
'post_type' => 'product',
'orderby' => 'ASC',
'posts_per_page'=>-1
);
$wp_query = new WP_Query($args);

