Get total number of authors on the site

How do I get total number of Authors on the site?

This shows summery of users on the site but I just want to get number of Authors.

<?php
$result = count_users();
echo 'There are ', $result['total_users'], ' total users';
foreach($result['avail_roles'] as $role => $count)
    echo ', ', $count, ' are ', $role, 's';
echo '.';
?>

https://codex.wordpress.org/Function_Reference/count_users

3 Answers
3

You can use the WP_User_Query class, like the example below. Each code line have an small description, that you understand, what we do.

// Get all users with role Author.
$user_query = new WP_User_Query( array( 'role' => 'Author' ) );
// Get the total number of users for the current query. I use (int) only for sanitize.
$users_count = (int) $user_query->get_total();
// Echo a string and the value
echo 'So much authors: ' . $users_count;

Alternative you can also use the function get_users(). But is only a wrapper for the query and have much more fields in the result.

Leave a Comment