Total number of authors with more than one post

<?php 
$users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users");
echo '(', count( get_users( array( 'role' => 'author' ) ) ); echo ')' 
?>

code by Jan Beck

I need to know what is my best option for displaying the total number of authors who have at least posted and/or published something on my blog.

Read More

Currently the code is counting all the authors even if they haven’t posted anything. Please let me know if there is a simple solution to this. I have looked throughout the wordpress codex and have not found a solution to this yet.

Related posts

1 comment

  1. I believe that wp_list_authors will do what you want, sort of. You could run the function with the echo parameter false and count the results.

    $authors = wp_list_authors(
      array(
        'echo'=>false,
        'html'=>false
      )
    );
    echo var_dump($authors);
    echo count (explode(',',$authors));
    

    Or, alternately, and perhaps less profligately, steal that function’s SQL.

    $authors = $wpdb->get_results(
      "SELECT DISTINCT post_author, COUNT(ID) AS count 
      FROM $wpdb->posts 
      WHERE post_type = 'post' 
      AND " . get_private_posts_cap_sql( 'post' ) . " 
      GROUP BY post_author"
    );
    var_dump($authors); 
    echo count($authors); 
    

    Those are slightly different in that the first ignores the admin user by default, but there is a parameter to change that.

Comments are closed.