On this page
wp_get_sites( array $args = array() ): array[]
This function has been deprecated. Use get_sites() instead.
Return an array of sites for a network or networks.
Description
See also
Parameters
$argsarray Optional-
Array of default arguments. Optional.
network_idint|int[]A network ID or array of network IDs. Set to null to retrieve sites from all networks. Defaults to current network ID.publicintRetrieve public or non-public sites. Default null, for any.archivedintRetrieve archived or non-archived sites. Default null, for any.matureintRetrieve mature or non-mature sites. Default null, for any.spamintRetrieve spam or non-spam sites. Default null, for any.deletedintRetrieve deleted or non-deleted sites. Default null, for any.limitintNumber of sites to limit the query to. Default 100.offsetintExclude the first x sites. Used in combination with the $limit parameter. Default 0.
Default:
array()
Return
array[] An empty array if the installation is considered "large" via wp_is_large_network() . Otherwise, an associative array of WP_Site data as arrays.
More Information
If wp_is_large_network() returns TRUE, wp_get_sites() will return an empty array. By default wp_is_large_network() returns TRUE if there are 10,000 or more sites in your network. This can be filtered using the wp_is_large_network filter.
Each site’s array is composed entirely of string values, even for numeric values. This means that == or !=, not === or !==, should be used to compare [blog_id] to get_current_blog_id() , which returns an integer value.
Source
File: wp-includes/ms-deprecated.php. View all references
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;
}
Related
Uses
| Uses | Description |
|---|---|
| get_current_network_id() wp-includes/load.php | Retrieves the current network ID. |
| get_sites() wp-includes/ms-site.php | Retrieves a list of sites matching requested arguments. |
| get_site() wp-includes/ms-site.php | Retrieves site data given a site ID or site object. |
| wp_is_large_network() wp-includes/ms-functions.php | Determines whether or not we have a large network. |
| _deprecated_function() wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. |
| wp_parse_args() wp-includes/functions.php | Merges user defined arguments into defaults array. |
Changelog
| Version | Description |
|---|---|
| 4.6.0 | Use get_sites() |
| 3.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_get_sites