Using WordPress ‘get_sitestats()’ PHP function

The get_sitestats() WordPress PHP function retrieves the network’s site and user counts.

Usage

$site_stats = get_sitestats();

Parameters

This function has no parameters.

More information

See WordPress Developer Resources: get_sitestats()

Examples

Display site and user count

Display the total number of sites and users on a WordPress multisite network.

$site_stats = get_sitestats();

echo 'Total Sites: ' . $site_stats['blogs'] . '<br>';
echo 'Total Users: ' . $site_stats['users'] . '<br>';

Display site count in a human-readable format

Display the site count in a human-readable format, such as “1,000” instead of “1000”.

$site_stats = get_sitestats();
$formatted_site_count = number_format($site_stats['blogs']);

echo 'Total Sites: ' . $formatted_site_count . '<br>';

Display user count in a human-readable format

Display the user count in a human-readable format, such as “1,000” instead of “1000”.

$site_stats = get_sitestats();
$formatted_user_count = number_format($site_stats['users']);

echo 'Total Users: ' . $formatted_user_count . '<br>';

Display percentage of users per site

Calculate and display the average percentage of users per site on a WordPress multisite network.

$site_stats = get_sitestats();
$percentage_users_per_site = ($site_stats['users'] / $site_stats['blogs']) * 100;

echo 'Percentage of Users per Site: ' . round($percentage_users_per_site, 2) . '%<br>';

Display user to site ratio

Display the user to site ratio on a WordPress multisite network.

$site_stats = get_sitestats();
$user_to_site_ratio = $site_stats['users'] / $site_stats['blogs'];

echo 'User to Site Ratio: ' . round($user_to_site_ratio, 2) . '<br>';