The get_sites() WordPress PHP function retrieves a list of sites matching the requested arguments.
Usage
$sites = get_sites( $args );
Custom example:
$args = array( 'number' => 5, 'order' => 'DESC' ); $sites = get_sites( $args );
Parameters
- $args (array|string) – Array or string of arguments. See WP_Site_Query::__construct() for information on accepted arguments.
More information
See WordPress Developer Resources: get_sites()
Examples
Get all sites
This example retrieves all sites from the database.
$sites = get_sites();
Get 10 most recently updated sites
This example retrieves the 10 most recently updated sites.
$args = array( 'number' => 10, 'orderby' => 'last_updated', 'order' => 'DESC' ); $recent_sites = get_sites( $args );
Get sites with a specific domain
This example retrieves sites with the domain “example.com”.
$args = array( 'domain' => 'example.com' ); $example_domain_sites = get_sites( $args );
Get sites with a specific path
This example retrieves sites with the path “/blog/”.
$args = array( 'path' => '/blog/' ); $blog_path_sites = get_sites( $args );
Get sites from a specific network
This example retrieves sites from a network with the ID of 2.
$args = array( 'network_id' => 2 ); $network_specific_sites = get_sites( $args );