Return an array of sites for a network or networks.
Description
See also
Parameters
$args
arrayoptional- Array of default arguments. Optional.
network_id
int|int[]A network ID or array of network IDs. Set to null to retrieve sites from all networks. Defaults to current network ID.public
intRetrieve public or non-public sites. Default null, for any.archived
intRetrieve archived or non-archived sites. Default null, for any.mature
intRetrieve mature or non-mature sites. Default null, for any.spam
intRetrieve spam or non-spam sites. Default null, for any.deleted
intRetrieve deleted or non-deleted sites. Default null, for any.limit
intNumber of sites to limit the query to. Default 100.offset
intExclude the first x sites. Used in combination with the $limit parameter. Default 0.
Default:
array()
Source
function wp_get_sites( $args = array() ) {
_deprecated_function( __FUNCTION__, '4.6.0', 'get_sites()' );
if ( wp_is_large_network() )
return array();
$defaults = array(
'network_id' => get_current_network_id(),
'public' => null,
'archived' => null,
'mature' => null,
'spam' => null,
'deleted' => null,
'limit' => 100,
'offset' => 0,
);
$args = wp_parse_args( $args, $defaults );
// Backward compatibility.
if( is_array( $args['network_id'] ) ){
$args['network__in'] = $args['network_id'];
$args['network_id'] = null;
}
if( is_numeric( $args['limit'] ) ){
$args['number'] = $args['limit'];
$args['limit'] = null;
} elseif ( ! $args['limit'] ) {
$args['number'] = 0;
$args['limit'] = null;
}
// Make sure count is disabled.
$args['count'] = false;
$_sites = get_sites( $args );
$results = array();
foreach ( $_sites as $_site ) {
$_site = get_site( $_site );
$results[] = $_site->to_array();
}
return $results;
}
Changelog
Version | Description |
---|---|
4.6.0 | Use get_sites() |
3.7.0 | Introduced. |
Basic Example
if you specify null to the ‘network_id’ then all site infomation in the network are returned.
Example of the array returned:
If you specified ‘1’ to the ‘network_id’ then the array that include only the first element must be returned.