Is there a plugin that counts posts by author?

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.

Related posts

Leave a Reply

1 comment

  1. I don’t know about a plugin but you can use this:

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

    <?php
    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:

    <?php
    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}
            {$where}
        ");
    $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:

    <?php
    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}
            {$where}
            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>';
    }
    ?>