Why does get_posts() return only 5 matching posts, when it should return 9?

Posted by Scott B on Stack Overflow See other posts from Stack Overflow or by Scott B
Published on 2010-01-25T18:14:53Z Indexed on 2012/09/29 15:38 UTC
Read the original article Hit count: 238

Filed under:
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;

The value of the echo is 5 (the correct value should be 9). The only way I can get it to return the correct value for the post count is to change the $myrecentposts2 calculation as follows...

$myrecentposts2 = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat1,-$cat2",'showposts' => 999));

© Stack Overflow or respective owner

Related posts about Wordpress