get_sites
Retrieves a list of sites matching requested arguments.
Description
(array) get_sites( (array) $args = array() );
Returns (array)
List of sites.
Parameters (1)
- 0. $args — Optional. (array) =>
array()
- Array or query string of site query parameters. Default empty.
Options
- site__in (array) =>
null
Array of site IDs to include.
- site__not_in (array) =>
null
Array of site IDs to exclude.
- count (bool) =>
false
Whether to return a site count (true) or array of site objects.
- date_query (array) =>
null
Date query clauses to limit sites by. See
WP_Date_Query
. - 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) =>
0
A site ID to only return that site.
- number (int) =>
100
Maximum number of sites to retrieve.
- offset (int) =>
0
Number of sites to offset the query. Used to build LIMIT clause.
- no_found_rows (bool) =>
true
Whether to disable the SQL_CALC_FOUND_ROWS query.
- orderby (string|array) =>
'id'
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.
- order (string) =>
'ASC'
How to order retrieved sites. Accepts ASC,, DESC..
- network_id (int) =>
0
Limit results to those affiliated with a given network ID. If 0, include all networks.
- network__in (array) =>
null
Array of network IDs to include affiliated sites for.
- network__not_in (array) =>
null
Array of network IDs to exclude affiliated sites for.
- domain (string) =>
''
Limit results to those affiliated with a given domain.
- domain__in (array) =>
null
Array of domains to include affiliated sites for.
- domain__not_in (array) =>
null
Array of domains to exclude affiliated sites for.
- path (string) =>
''
Limit results to those affiliated with a given path.
- path__in (array) =>
null
Array of paths to include affiliated sites for.
- path__not_in (array) =>
null
Array of paths to exclude affiliated sites for.
- public (int) =>
0
Limit results to public sites. Accepts 1 or 0..
- archived (int) =>
0
Limit results to archived sites. Accepts 1 or 0..
- mature (int) =>
0
Limit results to mature sites. Accepts 1 or 0..
- spam (int) =>
0
Limit results to spam sites. Accepts 1 or 0..
- deleted (int) =>
0
Limit results to deleted sites. Accepts 1 or 0..
- search (string) =>
''
Search term(s) to retrieve matching sites for.
- search_columns (array) =>
array()
Array of column names to be searched. Accepts domain and path..
array( /** * Array of site IDs to include. * * @type array * @default null */ 'site__in' => null, /** * Array of site IDs to exclude. * * @type array * @default null */ 'site__not_in' => null, /** * Whether to return a site count (true) or array of site objects. * * @type bool * @default false */ 'count' => false, /** * Date query clauses to limit sites by. See WP_Date_Query. * * @type array * @default null */ 'date_query' => null, /** * Site fields to return. Accepts 'ids' (returns an array of site IDs) or empty (returns an array * of complete site objects). * * @type string * @default '' */ 'fields' => '', /** * A site ID to only return that site. * * @type int */ 'ID' => 0, /** * Maximum number of sites to retrieve. * * @type int * @default 100 */ 'number' => 100, /** * Number of sites to offset the query. Used to build LIMIT clause. * * @type int */ 'offset' => 0, /** * Whether to disable the `SQL_CALC_FOUND_ROWS` query. * * @type bool * @default true */ 'no_found_rows' => true, /** * 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. * * @type string|array * @default 'id' */ 'orderby' => 'id', /** * How to order retrieved sites. Accepts 'ASC', 'DESC'. * * @type string * @default 'ASC' */ 'order' => 'ASC', /** * Limit results to those affiliated with a given network ID. If 0, include all networks. * * @type int */ 'network_id' => 0, /** * Array of network IDs to include affiliated sites for. * * @type array * @default null */ 'network__in' => null, /** * Array of network IDs to exclude affiliated sites for. * * @type array * @default null */ 'network__not_in' => null, /** * Limit results to those affiliated with a given domain. * * @type string * @default '' */ 'domain' => '', /** * Array of domains to include affiliated sites for. * * @type array * @default null */ 'domain__in' => null, /** * Array of domains to exclude affiliated sites for. * * @type array * @default null */ 'domain__not_in' => null, /** * Limit results to those affiliated with a given path. * * @type string * @default '' */ 'path' => '', /** * Array of paths to include affiliated sites for. * * @type array * @default null */ 'path__in' => null, /** * Array of paths to exclude affiliated sites for. * * @type array * @default null */ 'path__not_in' => null, /** * Limit results to public sites. Accepts '1' or '0'. * * @type int */ 'public' => 0, /** * Limit results to archived sites. Accepts '1' or '0'. * * @type int */ 'archived' => 0, /** * Limit results to mature sites. Accepts '1' or '0'. * * @type int */ 'mature' => 0, /** * Limit results to spam sites. Accepts '1' or '0'. * * @type int */ 'spam' => 0, /** * Limit results to deleted sites. Accepts '1' or '0'. * * @type int */ 'deleted' => 0, /** * Search term(s) to retrieve matching sites for. * * @type string * @default '' */ 'search' => '', /** * Array of column names to be searched. Accepts 'domain' and 'path'. * * @type array * @default array() */ 'search_columns' => array() );
…
- site__in (array) =>
Usage
if ( !function_exists( 'get_sites' ) ) { require_once ABSPATH . WPINC . '/ms-blogs.php'; } // Optional. Array or query string of site query parameters. Default empty. $args = array( 'site__in' => null, 'site__not_in' => null, 'count' => false, 'date_query' => null, 'fields' => '', 'ID' => 0, 'number' => 100, 'offset' => 0, 'no_found_rows' => true, 'orderby' => 'id', 'order' => 'ASC', 'network_id' => 0, 'network__in' => null, 'network__not_in' => null, 'domain' => '', 'domain__in' => null, 'domain__not_in' => null, 'path' => '', 'path__in' => null, 'path__not_in' => null, 'public' => 0, 'archived' => 0, 'mature' => 0, 'spam' => 0, 'deleted' => 0, 'search' => '', 'search_columns' => array() ); // NOTICE! Understand what this does before running. $result = get_sites($args);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/ms-blogs.php
- function get_sites( $args = array() ) {
- $query = new WP_Site_Query();
- return $query->query( $args );
- }