Using WordPress ‘get_blog_list()’ PHP function

The get_blog_list() WordPress PHP function retrieves a list of all sites on a WordPress Multisite installation. This function is deprecated, and it is recommended to use wp_get_sites() instead.

Usage

$blogs = get_blog_list($start, $num, $deprecated);

Custom Example

$blogs = get_blog_list(0, 5);
print_r($blogs);

This example retrieves the first 5 blogs from the list of sites.

Parameters

  • $start (int) (Optional): Offset for retrieving the blog list. Default is 0.
  • $num (int) (Optional): Number of blogs to list. Default is 10.
  • $deprecated (string) (Optional): Unused. Default is ”.

More information

See WordPress Developer Resources: get_blog_list

This function was deprecated in WordPress version 3.0.0. It is recommended to use wp_get_sites() instead. The source code for this function can be found in /wp-includes/ms-deprecated.php.

Examples

Basic Usage

Retrieve the first 10 blogs from the list of sites.

$blogs = get_blog_list();
print_r($blogs);

Custom Offset and Number of Blogs

Retrieve 7 blogs, starting from the 5th blog in the list.

$blogs = get_blog_list(4, 7);
print_r($blogs);

Retrieve All Blogs

To retrieve all blogs, use a high value for $num.

$blogs = get_blog_list(0, 99999);
print_r($blogs);

Display Blog IDs and URLs

Retrieve and display the first 10 blog IDs and URLs.

$blogs = get_blog_list();
foreach ($blogs as $blog) {
    echo "Blog ID: " . $blog['blog_id'] . " - URL: " . $blog['domain'] . $blog['path'] . "<br>";
}

Using wp_get_sites() Instead

As get_blog_list() is deprecated, use wp_get_sites() to retrieve the first 10 blogs.

$args = array('number' => 10);
$blogs = wp_get_sites($args);
print_r($blogs);