WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/count users

Description

Returns the count of users having each role, as well as the count of all users.

Usage

 <?php count_users$strategy ); ?> 

Parameters

$strategy
(string) (optional) 'time' or 'memory'. Generally, the default value 'time' is optimal due to the current schema design.
Default: 'time'

Return values

array 
Includes a grand total and an array of counts indexed by role strings.

Example

Default Usage

The call to count_users returns the number of users with each role. It will not return any roles having count == 0, so the results are intended to be used in foreach loops. <?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 
'.';
?>

There are 199 total users, 11 are administrators, 4 are contributors.

Source File

count_users() is located in wp-includes/user.php.

Change Log

  • Since: 3.0.0

Related

Count Tags: wp_count_posts(), wp_count_terms(), wp_count_comments(), count_users()

See also index of Function Reference and index of Template Tags.