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 have a page listing all the authors and the number of posts each of them has published. Is there a plugin that does this already? Being able to count number of comments as well would be a plus.

Thanks for the help.

share|improve this question

I don't know about a plugin but you can use this:

In author.php you can use this to count posts:

global $wp_query;
$curauth = $wp_query->get_queried_object();
$post_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '" . $curauth->ID . "' AND post_type = 'post' AND post_status = 'publish'");
<h2>Post Count: <?php echo $post_count; ?></h2>

Inside a Loop you can use this to count posts and comments:

global $wpdb;
$user_id = $post->post_author;  //change this if not in a std post loop
$where = 'WHERE comment_approved = 1 AND user_id = ' . $user_id ;
$comment_count = $wpdb->get_var(
    "SELECT COUNT( * ) AS total
        FROM {$wpdb->comments}
$user = get_userdata($user_id);
$post_count = get_usernumposts($user->ID);
echo '<p>User ' . $user->display_name . ' post count is ' . $post_count .', comment count is ' . $comment_count . '</p>';

For All Authors:

global $wpdb;
$where = 'WHERE comment_approved = 1 AND user_id <> 0';
$comment_counts = (array) $wpdb->get_results("
        SELECT user_id, COUNT( * ) AS total
        FROM {$wpdb->comments}
        GROUP BY user_id
    ", object);
foreach ( $comment_counts as $count ) {
  $user = get_userdata($count->user_id);
  $post_count = get_usernumposts($user->ID);
  echo '<p>User ' . $user->display_name . ' post count is ' . $post_count .', comment count is ' . $count->total . '</p>';
share|improve this answer
Thanks, Philip. I tried your first and second snippets and I made author.php display number of posts and number of comments. However, I couldn't get the third snippet to work. I created a page template and put your code in it, but it didn't work. I guess it doesn't work in a page template. I actually installed "Member List" plug-in and I wanted to use your code to display # of posts and comments in the member list page, but I couldn't get it to work either. PHP looks like Latin to me. Anyway, thanks for the answer. I will wait a bit more, if nobody knows plugins, I will mark your answer. – evergreen Apr 1 '11 at 0:20

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.