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()
);        


Usage

  1. if ( !function_exists( 'get_sites' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-blogs.php'; 
  3.  
  4. // Optional. Array or query string of site query parameters. Default empty. 
  5. $args = array( 
  6. 'site__in' => null, 
  7. 'site__not_in' => null, 
  8. 'count' => false, 
  9. 'date_query' => null, 
  10. 'fields' => '', 
  11. 'ID' => 0, 
  12. 'number' => 100, 
  13. 'offset' => 0, 
  14. 'no_found_rows' => true, 
  15. 'orderby' => 'id', 
  16. 'order' => 'ASC', 
  17. 'network_id' => 0, 
  18. 'network__in' => null, 
  19. 'network__not_in' => null, 
  20. 'domain' => '', 
  21. 'domain__in' => null, 
  22. 'domain__not_in' => null, 
  23. 'path' => '', 
  24. 'path__in' => null, 
  25. 'path__not_in' => null, 
  26. 'public' => 0, 
  27. 'archived' => 0, 
  28. 'mature' => 0, 
  29. 'spam' => 0, 
  30. 'deleted' => 0, 
  31. 'search' => '', 
  32. 'search_columns' => array() 
  33. ); 
  34.  
  35. // NOTICE! Understand what this does before running. 
  36. $result = get_sites($args); 
  37.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/ms-blogs.php  
  1. function get_sites( $args = array() ) { 
  2. $query = new WP_Site_Query(); 
  3.  
  4. return $query->query( $args );