On this page
wp_count_sites( int $network_id = null ): int[]
Count number of sites grouped by site status.
Parameters
$network_idint Optional-
The network to get counts for. Default is the current network ID.
Default:
null
Return
int[] Numbers of sites grouped by site status.
allintThe total number of sites.publicintThe number of public sites.archivedintThe number of archived sites.matureintThe number of mature sites.spamintThe number of spam sites.deletedintThe number of deleted sites.
Source
File: wp-includes/ms-blogs.php. View all references
function wp_count_sites( $network_id = null ) {
if ( empty( $network_id ) ) {
$network_id = get_current_network_id();
}
$counts = array();
$args = array(
'network_id' => $network_id,
'number' => 1,
'fields' => 'ids',
'no_found_rows' => false,
);
$q = new WP_Site_Query( $args );
$counts['all'] = $q->found_sites;
$_args = $args;
$statuses = array( 'public', 'archived', 'mature', 'spam', 'deleted' );
foreach ( $statuses as $status ) {
$_args = $args;
$_args[ $status ] = 1;
$q = new WP_Site_Query( $_args );
$counts[ $status ] = $q->found_sites;
}
return $counts;
}
Related
Uses
| Uses | Description |
|---|---|
| get_current_network_id() wp-includes/load.php | Retrieves the current network ID. |
| WP_Site_Query::__construct() wp-includes/class-wp-site-query.php | Sets up the site query, based on the query vars passed. |
Used By
| Used By | Description |
|---|---|
| WP_MS_Sites_List_Table::get_views() wp-admin/includes/class-wp-ms-sites-list-table.php | Gets links to filter sites by status. |
Changelog
| Version | Description |
|---|---|
| 5.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_count_sites