global $post;
$cat1=get_cat_ID('test1');
$cat2=get_cat_ID('test2');
$myrecentposts = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat1,-$cat2",'showposts' => 5));
$myrecentposts2 = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat1,-$cat2"));
$myrecentpostscount = count($myrecentposts2);
echo $myrecentpostscount;
echo 的值为 5(正确的值应该是 9)。我可以让它返回正确的帖子计数值的唯一方法是更改 $myrecentposts2 计算如下...
$myrecentposts2 = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat1,-$cat2",'showposts' => 999));
最佳答案
Wordpress 法典上写着 get_posts
有一个默认值 posts_per_page
5
的值.
要删除此限制,请使用 posts_per_page = -1
.
要取消此限制,您可以使用 nopaging = true
.
关于wordpress - 为什么 get_posts() 只返回 5 个匹配的帖子,而应该返回 9 个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2134500/