W3cubDocs

/WordPress

WP_Site_Query::__construct( string|array $query = '' )

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

Parameters

$query

(string|array) (Optional) Array or query string of site query parameters.

  • 'site__in'
    (array) Array of site IDs to include.
  • 'site__not_in'
    (array) Array of site IDs to exclude.
  • '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. 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).
  • 'ID'
    (int) A site ID to only return that site.
  • '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' and 'network__in'. Also accepts 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'
    (array) Array of network IDs to include affiliated sites for.
  • 'network__not_in'
    (array) Array of network IDs to exclude affiliated sites for.
  • 'domain'
    (string) Limit results to those affiliated with a given domain.
  • 'domain__in'
    (array) Array of domains to include affiliated sites for.
  • 'domain__not_in'
    (array) Array of domains to exclude affiliated sites for.
  • 'path'
    (string) Limit results to those affiliated with a given path.
  • 'path__in'
    (array) Array of paths to include affiliated sites for.
  • 'path__not_in'
    (array) Array of paths to exclude affiliated sites for.
  • 'public'
    (int) Limit results to public sites. Accepts '1' or '0'.
  • 'archived'
    (int) Limit results to archived sites. Accepts '1' or '0'.
  • 'mature'
    (int) Limit results to mature sites. Accepts '1' or '0'.
  • 'spam'
    (int) Limit results to spam sites. Accepts '1' or '0'.
  • 'deleted'
    (int) Limit results to deleted sites. Accepts '1' or '0'.
  • 'lang_id'
    (int) Limit results to a language ID.
  • 'lang__in'
    (array) Array of language IDs to include affiliated sites for.
  • 'lang__not_in'
    (array) Array of language IDs to exclude affiliated sites for.
  • 'search'
    (string) Search term(s) to retrieve matching sites for.
  • 'search_columns'
    (array) 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_query'
    (array) Meta query clauses to limit retrieved sites by. See WP_Meta_Query.
  • 'meta_key'
    (string) Limit sites to those matching a specific metadata key. Can be used in conjunction with $meta_value.
  • 'meta_value'
    (string) Limit sites to those matching a specific metadata value. Usually used in conjunction with $meta_key.
  • 'meta_type'
    (string) Data type that the $meta_value column will be CAST to for comparisons.
  • 'meta_compare'
    (string) Comparison operator to test the $meta_value.

Default value: ''

Source

File: wp-includes/class-wp-site-query.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 );
		}
	}

Changelog

Version Description
5.1.0 Introduced the 'update_site_meta_cache', 'meta_query', 'meta_key', 'meta_value', 'meta_type' and 'meta_compare' parameters.
4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters.
4.6.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_site_query/__construct