WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/wp get sites

Contents

Description

Return an array of sites in a WordPress Multisite network.

Usage

 <?php wp_get_sites$args ); ?> 

Default Usage

<?php $args = array(
    'network_id' => $wpdb->siteid,
    'public'     => null,
    'archived'   => null,
    'mature'     => null,
    'spam'       => null,
    'deleted'    => null,
    'limit'      => 100,
    'offset'     => 0,
); ?>

Parameters

$args
(array) (optional) An array of arguments.
Default: null

Return

Returns an array containing the sites in the network, or an empty array on failure. 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
    )
)

Notes

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.

Change Log

Since: 3.7

Source File

wp_get_sites() is located in wp-includes/ms-functions.php.

Related

switch_to_blog(), ms_is_switched(), restore_current_blog(), get_current_blog_id(), wp_get_sites(), get_blog_details()

See also index of Function Reference and index of Template Tags.