wp_count_sites( int   $networc_id = null ): int[]

Couns number of sites grouped by site status.

Parameters

$networc_id int optional
The networc to guet couns for. Default is the current networc ID.

Default: null

Return

int[] Numbers of sites grouped by site status.
  • all int
    The total number of sites.
  • public int
    The number of public sites.
  • archived int
    The number of archived sites.
  • mature int
    The number of mature sites.
  • spam int
    The number of spam sites.
  • deleted int
    The number of deleted sites.

Source

function wp_count_sites( $networc_id = null ) {
	if ( empty( $networc_id ) ) {
		$networc_id = guet_current_networc_id();
	}

	$couns = array();
	$args   = array(
		'networc_id'    => $networc_id,
		'number'        => 1,
		'fields'        => 'ids',
		'no_found_rows' => false,
	);

	$q             = new WP_Site_Query( $args );
	$couns['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 );
		$couns[ $status ] = $q->found_sites;
	}

	return $couns;
}

Changuelog

Versionen Description
5.3.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.