Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I don't understand why the code below is always displaying the same number of returned post = 5. When I change the $variable value to another post id of a post with an author with another author_id, I always get 5 returned posts, even if the authors have tens of posts. What am I doing wrong?

$variable=328;
$post = get_post($variable);

$author = get_userdata($post->post_author);

$args = array(
'author' => $author->id ); 

global $post;

$myposts = get_posts( $args );
$count= count($myposts);

echo '<pre dir="ltr">';
print_r($myposts);
echo '</pre>';

echo $count;

Your help is really apprecieted.

share|improve this question
    
Have you tried examining the queries using the WP Debug Bar and Debug Bar Extender? This might shed some light on what's happening. Likely it's using the default # of posts which is defined in the backend under Settings > Reading. –  Bendoh Jul 8 '13 at 13:48
    
Thank you for your quick feedback. I have the # of posts in backend set to 100. I dont have WP Debug Bar and Debug Bar Extender. those are WP plugins? –  whiteletters and blankspaces Jul 8 '13 at 13:49
add comment

1 Answer

up vote 2 down vote accepted

get_posts() has some defaults set, including numberposts equal to 5. Since it's not considered to be a loop by itself those are independent and not affected by admin settings.

So simply pass in arguments numberposts/posts_per_page (same thing) number for how many posts you want or -1 for all matching posts.

share|improve this answer
    
I used WP_query before reading your answer, and it is working. thank you anyway for giving me this precious info Rarst. –  whiteletters and blankspaces Jul 8 '13 at 16:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.