Title: WP_Site_Query::__construct
Published: August 16, 2016
Last modified: February 24, 2026

---

# WP_Site_Query::__construct( string|array $query )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/WP_Site_Query/__construct/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/WP_Site_Query/__construct/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/WP_Site_Query/__construct/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/WP_Site_Query/__construct/?output_format=md#changelog)

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

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

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

 `$query`string|arrayoptional

Array or query string of site query parameters. Default empty.

 * `site__in` int[]
 * Array of site IDs to include. Default empty.
 * `site__not_in` int[]
 * Array of site IDs to exclude. Default empty.
 * `count` bool
 * Whether to return a site count (true) or array of site objects.
    Default false.
 * `date_query` array
 * Date query clauses to limit sites by. See [WP_Date_Query](https://developer.wordpress.org/reference/classes/wp_date_query/).
   
   Default null.
 * `fields` string
 * Site fields to return. Accepts `'ids'` (returns an array of site IDs) or empty(
   returns an array of complete site objects). Default empty.
 * `ID` int
 * A site ID to only return that site. Default empty.
 * `number` int
 * Maximum number of sites to retrieve. Default 100.
 * `offset` int
 * Number of sites to offset the query. Used to build LIMIT clause.
    Default 0.
 * `no_found_rows` bool
 * Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
 * `orderby` string|array
 * Site status or array of statuses. Accepts:
    - `'id'`
    - `'domain'`
    - `'path'`
    - `'network_id'`
    - `'last_updated'`
    - `'registered'`
    - `'domain_length'`
    - `'path_length'`
    - `'site__in'`
    - `'network__in'`
    - `'deleted'`
    - `'mature'`
    - `'spam'`
    - `'archived'`
    - `'public'`
    - false, an empty array, or `'none'` to disable `ORDER BY` clause.
 *  Default `'id'`.
 * `order` string
 * How to order retrieved sites. Accepts `'ASC'`, `'DESC'`. Default `'ASC'`.
 * `network_id` int
 * Limit results to those affiliated with a given network ID. If 0, include all 
   networks. Default 0.
 * `network__in` int[]
 * Array of network IDs to include affiliated sites for. Default empty.
 * `network__not_in` int[]
 * Array of network IDs to exclude affiliated sites for. Default empty.
 * `domain` string
 * Limit results to those affiliated with a given domain. Default empty.
 * `domain__in` string[]
 * Array of domains to include affiliated sites for. Default empty.
 * `domain__not_in` string[]
 * Array of domains to exclude affiliated sites for. Default empty.
 * `path` string
 * Limit results to those affiliated with a given path. Default empty.
 * `path__in` string[]
 * Array of paths to include affiliated sites for. Default empty.
 * `path__not_in` string[]
 * Array of paths to exclude affiliated sites for. Default empty.
 * `public` int
 * Limit results to public sites. Accepts 1 or 0. Default empty.
 * `archived` int
 * Limit results to archived sites. Accepts 1 or 0. Default empty.
 * `mature` int
 * Limit results to mature sites. Accepts 1 or 0. Default empty.
 * `spam` int
 * Limit results to spam sites. Accepts 1 or 0. Default empty.
 * `deleted` int
 * Limit results to deleted sites. Accepts 1 or 0. Default empty.
 * `lang_id` int
 * Limit results to a language ID. Default empty.
 * `lang__in` string[]
 * Array of language IDs to include affiliated sites for. Default empty.
 * `lang__not_in` string[]
 * Array of language IDs to exclude affiliated sites for. Default empty.
 * `search` string
 * Search term(s) to retrieve matching sites for. Default empty.
 * `search_columns` string[]
 * Array of column names to be searched. Accepts `'domain'` and `'path'`.
    Default
   empty array.
 * `update_site_cache` bool
 * Whether to prime the cache for found sites. Default true.
 * `update_site_meta_cache` bool
 * Whether to prime the metadata cache for found sites. Default true.
 * `meta_key` string|string[]
 * Meta key or keys to filter by.
 * `meta_value` string|string[]
 * Meta value or values to filter by.
 * `meta_compare` string
 * MySQL operator used for comparing the meta value.
    See [WP_Meta_Query::__construct()](https://developer.wordpress.org/reference/classes/wp_meta_query/__construct/)
   for accepted values and default value.
 * `meta_compare_key` string
 * MySQL operator used for comparing the meta key.
    See [WP_Meta_Query::__construct()](https://developer.wordpress.org/reference/classes/wp_meta_query/__construct/)
   for accepted values and default value.
 * `meta_type` string
 * MySQL data type that the meta_value column will be CAST to for comparisons.
    
   See [WP_Meta_Query::__construct()](https://developer.wordpress.org/reference/classes/wp_meta_query/__construct/)
   for accepted values and default value.
 * `meta_type_key` string
 * MySQL data type that the meta_key column will be CAST to for comparisons.
    See
   [WP_Meta_Query::__construct()](https://developer.wordpress.org/reference/classes/wp_meta_query/__construct/)
   for accepted values and default value.
 * `meta_query` array
 * An associative array of [WP_Meta_Query](https://developer.wordpress.org/reference/classes/wp_meta_query/)
   arguments.
    See [WP_Meta_Query::__construct()](https://developer.wordpress.org/reference/classes/wp_meta_query/__construct/)
   for accepted values.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/WP_Site_Query/__construct/?output_format=md#source)󠁿

    ```php
    public function __construct( $query = '' ) {
    	$this->query_var_defaults = array(
    		'fields'                 => '',
    		'ID'                     => '',
    		'site__in'               => '',
    		'site__not_in'           => '',
    		'number'                 => 100,
    		'offset'                 => '',
    		'no_found_rows'          => true,
    		'orderby'                => 'id',
    		'order'                  => 'ASC',
    		'network_id'             => 0,
    		'network__in'            => '',
    		'network__not_in'        => '',
    		'domain'                 => '',
    		'domain__in'             => '',
    		'domain__not_in'         => '',
    		'path'                   => '',
    		'path__in'               => '',
    		'path__not_in'           => '',
    		'public'                 => null,
    		'archived'               => null,
    		'mature'                 => null,
    		'spam'                   => null,
    		'deleted'                => null,
    		'lang_id'                => null,
    		'lang__in'               => '',
    		'lang__not_in'           => '',
    		'search'                 => '',
    		'search_columns'         => array(),
    		'count'                  => false,
    		'date_query'             => null, // See WP_Date_Query.
    		'update_site_cache'      => true,
    		'update_site_meta_cache' => true,
    		'meta_query'             => '',
    		'meta_key'               => '',
    		'meta_value'             => '',
    		'meta_type'              => '',
    		'meta_compare'           => '',
    	);

    	if ( ! empty( $query ) ) {
    		$this->query( $query );
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-site-query.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-site-query.php#L188)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-site-query.php#L188-L232)

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

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

Sets up the WordPress query for retrieving sites.

  |

| Used by | Description | 
| [wp_count_sites()](https://developer.wordpress.org/reference/functions/wp_count_sites/)`wp-includes/ms-blogs.php` |

Counts number of sites grouped by site status.

  | 
| [get_sites()](https://developer.wordpress.org/reference/functions/get_sites/)`wp-includes/ms-site.php` |

Retrieves a list of sites matching requested arguments.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/WP_Site_Query/__construct/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Introduced the `'meta_type_key'` parameter. | 
| [5.1.0](https://developer.wordpress.org/reference/since/5.1.0/) | Introduced the `'update_site_meta_cache'`, `'meta_query'`, `'meta_key'`, `'meta_compare_key'`, `'meta_value'`, `'meta_type'`, and `'meta_compare'` parameters. | 
| [4.8.0](https://developer.wordpress.org/reference/since/4.8.0/) | Introduced the `'lang_id'`, `'lang__in'`, and `'lang__not_in'` parameters. | 
| [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. |

## User Contributed Notes

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