wp_get_sites()
Gets an array with data from all sites in the network or networks.
No Hooks.
Returns
Array[].
-
array()- an empty array when there are more than 10,000 sites in the network. This setting is considered "large". The function wp_is_large_network() checks this, and its result can be modified through the filter: wp_is_large_network. Associative array- an array whose elements will be arrays with data for each site in the network.
Example of what the function will return:
Array( [0] => Array( [blog_id] => 1 [site_id] => 1 [domain] => example.com [path] => / [registered] => 2013-11-08 17:56:46 [last_updated] => 2013-11-08 18:57:19 [public] => 1 [archived] => 0 [mature] => 0 [spam] => 0 [deleted] => 0 [lang_id] => 0 ) [1] => Array( [blog_id] => 2 ... ) )
Each value in the array of each site is a string, even when it contains an int. Therefore, when checking integers, for example blog_id, use comparison operators == or !=, not === or !==.
Usage
$sites = wp_get_sites( $args );
- $args(array)
Array of parameters by which the sites of the network will be obtained. Understands the following array keys:
-
network_id(int|array)
ID of the network whose sites need to be obtained. Multiple IDs can be specified in an array.
Default: null (current network) -
public(int)
Which sites to get: public or not.
Default: null (any) -
archived(int)
Which sites to get: those in the archive or not.
Default: null (any) -
mature(int)
Which sites to get: launched or not.
Default: null (any) -
spam(int)
Which sites to get: those in spam or not.
Default: null (any) -
deleted(int)
Which sites to get: those deleted (in the trash) or "live".
Default: null (any) -
limit(int)
Limit on the number of sites to be obtained.
Default: 100 - offset(int)
Upper offset (slice) from the number of sites. Used in combination with the limit parameter.
Default: 0
Default: array()
-
Examples
#1 Get all the sites in the network as an array
$array = wp_get_sites( array( 'network_id' => null, 'public' => null, 'archived' => null, 'mature' => null, 'spam' => null, 'deleted' => null, 'limit' => 100, 'offset' => 0, ) ); print_r( $array ); /* Will display Array( [0] => Array( [blog_id] => 1 [site_id] => 1 [domain] => example.com [path] => / [registered] => 2013-11-08 17:56:46 [last_updated] => 2013-11-08 18:57:19 [public] => 1 [archived] => 0 [mature] => 0 [spam] => 0 [deleted] => 0 [lang_id] => 0 ) [1] => Array( [blog_id] => 2 [site_id] => 1 [domain] => example.com [path] => /examplesubsite/ [registered] => 2013-11-08 18:07:22 [last_updated] => 2013-11-08 18:13:40 [public] => 1 [archived] => 0 [mature] => 0 [spam] => 0 [deleted] => 0 [lang_id] => 0 ) ) */
Notes
- See: get_sites()
Changelog
| Since 3.7.0 | Introduced. |
| Deprecated since 4.6.0 | Use get_sites() |