wp_count_sites( int $network_id = null ): int[]
Counts number of sites grouped by site status.
Parameters
-
$network_id
int Optional -
The network to get counts for. Default is the current network ID.
Default:
null
Return
int[] Numbers of sites grouped by site status.
all
intThe total number of sites.public
intThe number of public sites.archived
intThe number of archived sites.mature
intThe number of mature sites.spam
intThe number of spam sites.deleted
intThe 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;
}
Changelog
Version | Description |
---|---|
5.3.0 | Introduced. |