WP_Site[]|int[]|int List of WP_Site objects, a list of site IDs when 'fields' is set to 'ids', or the number of sites when 'count' is passed as a query var.
Beware, using get_sites() as a drop-in for wp_get_sites() may not produce results as expected.
PHP Fatal error: Cannot use object of type WP_Site as array in /path/to/code/that/uses/get_sites/method/file.php
It’s true that get_sites() returns an array, however, it produces an array of sites as objects. This is different from wp_get_sites(), which used to produce a multidimensional array of the sites, with their properties in a secondary array dimension (simply an array of site arrays with that site’s properties).
Also good to know… get_sites now returns an OBJECT not a named array.
A code example that may help:
Beware, using
get_sites()as a drop-in forwp_get_sites()may not produce results as expected.PHP Fatal error: Cannot use object of type WP_Site as array in /path/to/code/that/uses/get_sites/method/file.phpIt’s true that
get_sites()returns an array, however, it produces an array of sites as objects. This is different fromwp_get_sites(), which used to produce a multidimensional array of the sites, with their properties in a secondary array dimension (simply an array of site arrays with that site’s properties).If you’re attempting to loop through the sites to get the properties of each site with get_sites() , you’ll need to convert each site object to an array using
get_object_vars( object )https://www.php.net/manual/en/function.get-object-vars.php.See the example below noting the use of get_object_vars on line three:
This should return the following list of sites:
Site ID/Name: 1 / SiteNameOne
Site ID/Name: 2 / SiteNameTwo
Site ID/Name: 3 / SiteNameThree
wp_get_sites() ‘limit’ argument is now ‘number’.
wp_get_sites() converted this to $args[‘number’] for you, get_sites() does not appear to handle this parameter name conversion for you.
Reference: https://developer.wordpress.org/reference/functions/wp_get_sites/
The number of sites returned is limited to 100 by default. you can increase this using
number.Note that -1 (often used to “get all”) does not appear to work here.