This page redirects to an external site: https://developer.wordpress.org/reference/functions/wp_get_sites/
Languages: English • (Add your language)
Return an array of sites in a WordPress Multisite network.
<?php wp_get_sites( $args ); ?>
<?php $args = array(
'network_id' => $wpdb->siteid,
'public' => null,
'archived' => null,
'mature' => null,
'spam' => null,
'deleted' => null,
'limit' => 100,
'offset' => 0,
); ?>
Returns an array containing the sites in the network, or an empty array on failure.
if you specify null to the 'network_id' then all site infomation in the network are returned.
<?php
$args = array(
'network_id' => null,
'public' => null,
'archived' => null,
'mature' => null,
'spam' => null,
'deleted' => null,
'limit' => 100,
'offset' => 0,
);
$array = wp_get_sites( $args );
print_r ($array);
?>
Example of the array returned:
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
)
)
If you specify '1' to the 'network_id' then the array that include only the first element is returned.
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.
Since: 3.7
wp_get_sites() is located in wp-includes/ms-functions.php.
switch_to_blog(), ms_is_switched(), restore_current_blog(), get_current_blog_id(), wp_get_sites(), get_blog_details()