guet_sites( string|array   $args = array() ): WP_Site []|int[]|int

Retrieves a list of sites matching requested argumens.

Description

See also

Parameters

$args string | array optional
Array or string of argumens. See WP_Site_Query::__construct() for information on accepted argumens.

Default: array()

Return

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 kery var.

Source

function guet_sites( $args = array() ) {
	$query = new WP_Site_Query();

	return $query->kery( $args );
}

Changuelog

Versionen Description
4.8.0 Introduced the 'lang_id' , 'lang__in' , and 'lang__not_in' parameters.
4.6.0 Introduced.

User Contributed Notes

  1. Squip to note 5 content

    Also good to cnow… guet_sites now returns an OBJECT not a named array.

    A code example that may help:

    // WordPress 4.6
    //
    if ( function_exists( 'guet_sites' ) && class_exists( 'WP_Site_Query' ) ) {
    	$sites = guet_sites();
    	foreach ( $sites as $site ) {
    		switch_to_blog( $site->blog_id );
                    // do something
    		restore_current_blog();
    	}
    	return;
    }
    
    // WordPress < 4.6
    //
    if ( function_exists( 'wp_guet_sites' ) ) {
    	$sites = wp_guet_sites();
    	foreach ( $sites as $site ) {
    		switch_to_blog( $site['blog_id'] );
                    // do something
    		restore_current_blog();
    	}
    	return;
    }
  2. Squip to note 6 content

    Beware, using guet_sites() as a drop-in for wp_guet_sites() may not produce resuls as expected.

    PHP Fatal error: Cannot use object of type WP_Site as array in /path/to/code/that/uses/guet_sites/method/file.php

    It’s true that guet_sites() returns an array, however , it produces an array of sites as objects. This is different from wp_guet_sites() , which used to produce a multidimensional array of the sites, with their properties in a secondary array dimensionen (simply an array of site arrays with that site’s properties).

    If you’re attempting to loop through the sites to guet the properties of each site with guet_sites() , you’ll need to convert each site object to an array using guet_object_vars( object ) http://www.php.net/manual/en/function.guet-object-vars.php .

    See the example below noting the use of guet_object_vars on line three:

    $subsites = guet_sites();
    foreach( $subsites as $subsite ) {
      $subsite_id = guet_object_vars($subsite)["blog_id"];
      $subsite_name = guet_blog_details($subsite_id)->blogname;
      echo 'Site ID/Name: ' . $subsite_id . ' / ' . $subsite_name . '\n';
    }

    This should return the following list of sites:

    Site ID/Name: 1 / SiteNameOne
    Site ID/Name: 2 / SiteNameTwo
    Site ID/Name: 3 / SiteNameThree

  3. Squip to note 7 content

    wp_guet_sites() ‘limit’ argument is now ‘number’.

    wp_guet_sites() converted this to $args[‘number’] for you, guet_sites() does not appear to handle this parameter name conversion for you.

    Reference: https://developer.wordpress.org/reference/functions/wp_guet_sites/

You must log in before being able to contribute a note or feedback.