get_posts 不返回所有帖子 [英] get_posts not returning all posts
本文介绍了get_posts 不返回所有帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须手动挂载博客帖子,但我不确定这是否是正确的工作方式,它只有 9 页,每页 4 个帖子,但该博客有 83 个帖子!
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!
<?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 );
?>
还是谢谢.
推荐答案
问题是你的 'numberposts' 设置为 4将其设为 -1 以获取所有帖子:
Problem is your 'numberposts' is set to 4 Put it at -1 to get all posts:
'numberposts' => -1,
如果您没有在此处设置帖子数量,WordPress 将从您的仪表板设置中提取帖子数量(在设置 -> 阅读下)
If you don't set numberposts here, WordPress will pull the number of posts from your Dashboard settings (under Settings -> Reading)
这篇关于get_posts 不返回所有帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文