I have been searching high and low for a way to count the amount of results from a get_users query.

Most of what I found is to count the total number of posts in a post query, but nothing for counting the total number of users in the get_users query.

Can someone point it out for me? Thanks a lot.

4 Answers 4


when you use get_users() it retrieves an array of users matching the criteria given in $args which means you can simply use PHP's count() function e.g:

$users = get_users($args);
$number_of_users = count($users);
  • 1
    That answer is incorrect as get_users() only returns the requested number of results, i.e. 10, 20 etc... There may be more. Sep 12, 2012 at 23:10
  • umm, that is true if you set the number parameter but if not (which obviously is the case here) then This answer is correct!
    – Bainternet
    Sep 13, 2012 at 8:58

Bainternet's answer gives you the number of users for one query and doesn't help if you need multiple pages of users.

If you have thousands of users that's not what you want. You can use WP_User_Query much the same way you use WP_Query for posts. It's very similar to get_users -- same arguments, but different features and usage.

Most importantly you can get the total number of users who match your criteria without actually returning all of the results (and potentially hitting memory limits).


$user_query = new WP_User_Query(array(
    'number' => 15,
    'paged' => 1

$users = $user_query->get_results(); // array of WP_User objects, like get_users

$total = $user_query->get_total(); // int, total number of users (not just the first page)


echo $users[0]->get('display_name');
// "Radley Sustaire"

echo count($users);
// "15" (count from the first page of users)

echo $user_query->get_total();
// "86" (count from all pages of users)

$num_pages = ceil( $user_query->get_total() / 15 );
// "6" (number of pages of users. 15 is the "users per page" from the first example)
//     (* do NOT use count($users) in place of 15. try a separate $per_page variable)
  • $user_query->get_total(); that really saved my day ;) Thank you. Aug 30, 2021 at 3:41
  • @Radley Sustaire, what if you want to get the total number of users as well as the number of "Authors" for example? What hook do you have to call or use?
    – Motivated
    Sep 5, 2022 at 19:32
  • @Motivated To use WP_User_Query you will need to do a second separate query and add the argument 'role' => 'author' (below the line with 'paged' => 1). To clarify $users->get_total() gets the total users which matched the query. Sep 6, 2022 at 18:58

Here is how I implemented this:

function getUsers($args = array(), $count = false)
    // Default behaviour is to return full user information
    $method = 'get_results';

    // If count is true then change the WP_User_Query method
    // and limit the fields SELECT'd to 'ID' to speed up the query
    if($count === true) {
        $method = 'get_total';
        $args['fields'] = 'ID';

    $userQuery = new WP_User_Query($userArgs);

    return call_user_func(array($userQuery, $method));


$args = array('role' => author,
              'meta_key' => 'foo',
              'meta_value' => 'bar'

// Returns (array) WP_User objects (a la get_users())
$users = getUsers($args);

// Returns (int) number of of users matched by $args
$count = getUsers($args, true);

Aside from being more compact / reusable than $users = get_users($args); $count = count($users); it ensures that if all you want is the total number then it will fetch the minimum required from the DB to achieve this.


Try the function below to get the count of all users, and user counts based on user roles, in an array:


Output comes like this:

Array (
    [total_users] => 32
    [avail_roles] => Array (
        [administrator] => 1
        [subscriber] => 28
        [sub_administrator] => 1
        [editor] => 2

More information can be found here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.