WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to list all the users of my site and the amount of posts each user has.

So far I have the function below, but I don't know how to pull in each user's ID to use in the count_user_posts...

<?php foreach ( get_users('order=DESC&orderby=post_count') as $user ) : ?>
    <li style="color:#fff;"><span style="font-weight:bold;">
    <?php echo $user->display_name; ?></span> as <?php echo $user->user_nicename; ?> (<?php echo $user->post_count; ?> Posts)<br />
    <?php echo 'Posts made: ' . count_user_posts(1); ?>
    </li><br />
<?php endforeach; ?>

I have foreach function going, but count_user_posts requires an integer I don't pull in each individual user ID to grab their post amount.

I would appreciate some help with this. I know it's probably something simple... I'm kind of new to php :D. Thanks a lot.

share|improve this question
up vote 2 down vote accepted

WordPress has a wp_list_authors function with the option to list post count.

$args = array( 'orderby' => 'post_count', 'optioncount' => true);
wp_list_authors( $args );

EDIT: While it's possible to do it the way you're doing it and use count_user_posts(), this will trigger a query to retrieve users, then additional queries to get each user's count. this is a very inefficient way to do this and may have a significant impact on performance if you have a lot of authors. A better way is to select users, and count the posts all in one query. If you look in wp-includes/author-template.php you'll see the query wp_list_authors generates to do this.

share|improve this answer
Thanks this is exactly what I needed! – user1893 May 3 '11 at 16:18
<?php echo 'Posts made: ' . count_user_posts($user->ID); ?>
share|improve this answer

Your Answer


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.