<?php
$users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users");
echo '(', count( get_users( array( 'role' => 'author' ) ) ); echo ')'
?>
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.
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.
I believe that
wp_list_authors
will do what you want, sort of. You could run the function with theecho
parameter false and count the results.Or, alternately, and perhaps less profligately, steal that function’s
SQL
.Those are slightly different in that the first ignores the admin user by default, but there is a parameter to change that.