Title: wp_count_sites
Published: November 12, 2019
Last modified: February 24, 2026

---

# wp_count_sites( int $network_id = null ): int[]

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_count_sites/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_count_sites/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_count_sites/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_count_sites/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_count_sites/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_count_sites/?output_format=md#wp--skip-link--target)

Counts number of sites grouped by site status.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_count_sites/?output_format=md#parameters)󠁿

 `$network_id`intoptional

The network to get counts for. Default is the current network ID.

Default:`null`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_count_sites/?output_format=md#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](https://developer.wordpress.org/reference/functions/wp_count_sites/?output_format=md#source)󠁿

    ```php
    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;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/ms-blogs.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/ms-blogs.php#L944)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/ms-blogs.php#L944-L972)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_count_sites/?output_format=md#related)󠁿

| Uses | Description | 
| [get_current_network_id()](https://developer.wordpress.org/reference/functions/get_current_network_id/)`wp-includes/load.php` |

Retrieves the current network ID.

  | 
| [WP_Site_Query::__construct()](https://developer.wordpress.org/reference/classes/wp_site_query/__construct/)`wp-includes/class-wp-site-query.php` |

Sets up the site query, based on the query vars passed.

  |

| Used by | Description | 
| [WP_MS_Sites_List_Table::get_views()](https://developer.wordpress.org/reference/classes/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](https://developer.wordpress.org/reference/functions/wp_count_sites/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_count_sites%2F)
before being able to contribute a note or feedback.