wordpress / latest / functions / get_sites.html

get_sites( string|array $args = array() ): array|int

Retrieves a list of sites matching requested arguments.

Description

See also

Parameters

$args string|array Optional
Array or string of arguments. See WP_Site_Query::__construct() for information on accepted arguments.
More Arguments from WP_Site_Query::__construct( ... $query ) Array or query string of site query parameters.
  • site__inint[]
    Array of site IDs to include.
  • site__not_inint[]
    Array of site IDs to exclude.
  • countbool
    Whether to return a site count (true) or array of site objects.
    Default false.
  • date_queryarray
    Date query clauses to limit sites by. See WP_Date_Query.
    Default null.
  • fieldsstring
    Site fields to return. Accepts 'ids' (returns an array of site IDs) or empty (returns an array of complete site objects).
  • IDint
    A site ID to only return that site.
  • numberint
    Maximum number of sites to retrieve. Default 100.
  • offsetint
    Number of sites to offset the query. Used to build LIMIT clause.
    Default 0.
  • no_found_rowsbool
    Whether to disable the SQL_CALC_FOUND_ROWS query. Default true.
  • orderbystring|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'.
  • orderstring
    How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'.
  • network_idint
    Limit results to those affiliated with a given network ID. If 0, include all networks. Default 0.
  • network__inint[]
    Array of network IDs to include affiliated sites for.
  • network__not_inint[]
    Array of network IDs to exclude affiliated sites for.
  • domainstring
    Limit results to those affiliated with a given domain.
  • domain__instring[]
    Array of domains to include affiliated sites for.
  • domain__not_instring[]
    Array of domains to exclude affiliated sites for.
  • pathstring
    Limit results to those affiliated with a given path.
  • path__instring[]
    Array of paths to include affiliated sites for.
  • path__not_instring[]
    Array of paths to exclude affiliated sites for.
  • publicint
    Limit results to public sites. Accepts '1' or '0'.
  • archivedint
    Limit results to archived sites. Accepts '1' or '0'.
  • matureint
    Limit results to mature sites. Accepts '1' or '0'.
  • spamint
    Limit results to spam sites. Accepts '1' or '0'.
  • deletedint
    Limit results to deleted sites. Accepts '1' or '0'.
  • lang_idint
    Limit results to a language ID.
  • lang__instring[]
    Array of language IDs to include affiliated sites for.
  • lang__not_instring[]
    Array of language IDs to exclude affiliated sites for.
  • searchstring
    Search term(s) to retrieve matching sites for.
  • search_columnsstring[]
    Array of column names to be searched. Accepts 'domain' and 'path'.
    Default empty array.
  • update_site_cachebool
    Whether to prime the cache for found sites. Default true.
  • update_site_meta_cachebool
    Whether to prime the metadata cache for found sites. Default true.
  • meta_keystring|string[]
    Meta key or keys to filter by.
  • meta_valuestring|string[]
    Meta value or values to filter by.
  • meta_comparestring
    MySQL operator used for comparing the meta value.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_compare_keystring
    MySQL operator used for comparing the meta key.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_typestring
    MySQL data type that the meta_value column will be CAST to for comparisons.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_type_keystring
    MySQL data type that the meta_key column will be CAST to for comparisons.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_queryarray
    An associative array of WP_Meta_Query arguments.
    See WP_Meta_Query::__construct() for accepted values.

Default: array()

Return

array|int List of WP_Site objects, a list of site IDs when 'fields' is set to 'ids', or the number of sites when 'count' is passed as a query var.

Source

File: wp-includes/ms-site.php. View all references

function get_sites( $args = array() ) {
	$query = new WP_Site_Query();

	return $query->query( $args );
}

Uses

Uses Description

Used By

Used By Description

Changelog

Version Description
4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters.
4.6.0 Introduced.

© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_sites