wp_get_sites

Return an array of sites for a network or networks.

Description

(array) wp_get_sites( (array) $args = array() ); 

Returns (array)

An empty array if the install is considered "large" via wp_is_large_network(). Otherwise, an associative array of site data arrays, each containing the site (network) ID, blog ID, site domain and path, dates registered and modified, and the language ID. Also, boolean values for whether the site is public, archived, mature, spam, and/or deleted.

Parameters (1)

0. $args — Optional. (array) => array()
Array of default arguments. Optional.

Options

  • network_id (int|array) => to current network ID

    A network ID or array of network IDs. Set to null to retrieve sites from all networks.

  • public (int) => null, for any

    Retrieve public or non-public sites.

  • archived (int) => null, for any

    Retrieve archived or non-archived sites.

  • mature (int) => null, for any

    Retrieve mature or non-mature sites.

  • spam (int) => null, for any

    Retrieve spam or non-spam sites.

  • deleted (int) => null, for any

    Retrieve deleted or non-deleted sites.

  • limit (int) => 100

    Number of sites to limit the query to.

array(

    /**
     * A network ID or array of network IDs. Set to null to retrieve sites from all networks.
     *
     * @type int|array
     * @default to current network ID
     */
    'network_id' => to current network ID,

    /**
     * Retrieve public or non-public sites.
     *
     * @type int
     * @default null, for any
     */
    'public' => null, for any,

    /**
     * Retrieve archived or non-archived sites.
     *
     * @type int
     * @default null, for any
     */
    'archived' => null, for any,

    /**
     * Retrieve mature or non-mature sites.
     *
     * @type int
     * @default null, for any
     */
    'mature' => null, for any,

    /**
     * Retrieve spam or non-spam sites.
     *
     * @type int
     * @default null, for any
     */
    'spam' => null, for any,

    /**
     * Retrieve deleted or non-deleted sites.
     *
     * @type int
     * @default null, for any
     */
    'deleted' => null, for any,

    /**
     * Number of sites to limit the query to.
     *
     * @type int
     * @default 100
     */
    'limit' => 100
);        


Usage

  1. if ( !function_exists( 'wp_get_sites' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-deprecated.php'; 
  3.  
  4. // Array of default arguments. Optional. 
  5. $args = array( 
  6. 'network_id' => to current network ID, 
  7. 'public' => null, for any, 
  8. 'archived' => null, for any, 
  9. 'mature' => null, for any, 
  10. 'spam' => null, for any, 
  11. 'deleted' => null, for any, 
  12. 'limit' => 100 
  13. ); 
  14.  
  15. // NOTICE! Understand what this does before running. 
  16. $result = wp_get_sites($args); 
  17.  

Defined (1)

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

/wp-includes/ms-deprecated.php  
  1. function wp_get_sites( $args = array() ) { 
  2. global $wpdb; 
  3.  
  4. _deprecated_function( __FUNCTION__, '4.6.0', 'get_sites()' ); 
  5.  
  6. return array(); 
  7.  
  8. $defaults = array( 
  9. 'network_id' => $wpdb->siteid,  
  10. 'public' => null,  
  11. 'archived' => null,  
  12. 'mature' => null,  
  13. 'spam' => null,  
  14. 'deleted' => null,  
  15. 'limit' => 100,  
  16. 'offset' => 0,  
  17. ); 
  18.  
  19. $args = wp_parse_args( $args, $defaults ); 
  20.  
  21. // Backwards compatibility 
  22. if( is_array( $args['network_id'] ) ) { 
  23. $args['network__in'] = $args['network_id']; 
  24. $args['network_id'] = null; 
  25.  
  26. if( is_numeric( $args['limit'] ) ) { 
  27. $args['number'] = $args['limit']; 
  28. $args['limit'] = null; 
  29.  
  30. // Make sure count is disabled. 
  31. $args['count'] = false; 
  32.  
  33. $_sites = get_sites( $args ); 
  34.  
  35. $results = array(); 
  36.  
  37. foreach ( $_sites as $_site ) { 
  38. $_site = get_site( $_site ); 
  39. $results[] = $_site->to_array(); 
  40.  
  41. return $results;