wordpress get_posts 不返回所有帖子
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12010497/
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
get_posts not returning all posts
提问by Rafael Moni
I have to mount the blog posts manually, but I'm not sure if this is the correct way to work, It only brings 9 pages, with 4 posts each, but the blog has 83 posts!
我必须手动挂载博客文章,但我不确定这是否是正确的工作方式,它只有 9 页,每页 4 篇文章,但博客有 83 篇文章!
<?php
$paged = get_query_var('paged');
$args = array(
'numberposts' => 4,
'offset' => $paged*4,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'suppress_filters' => true
);
$posts_array = get_posts( $args );
?>
Thanks anyway.
不管怎么说,还是要谢谢你。
回答by AJ Zane
Problem is your 'numberposts' is set to 4 Put it at -1 to get all posts:
问题是您的 'numberposts' 设置为 4 将其设置为 -1 以获取所有帖子:
'numberposts' => -1,
If you don't set numberposts here, WordPress will pull the number of posts from your Dashboard settings (under Settings -> Reading)
如果您没有在此处设置帖子数,WordPress 将从您的仪表板设置中提取帖子数(在设置 -> 阅读下)
回答by Libin
The below note is from this codex section.
以下注释来自此法典部分。
Note: With use of the offset, the above query should be used only on a category that has more than one post in it, otherwise there'll be no output.
注意:使用偏移量,上面的查询只能用于包含多个帖子的类别,否则将没有输出。
So in-order to display all posts, there should be at-least 2 posts in each categories.
因此,为了显示所有帖子,每个类别至少应有 2 个帖子。
You can try Loopsto get all posts. Check The Loop in Actionalso.