get_id_from_blogname()
Retrieves a sites ID given its (subdomain or directory) slug.
Uses: get_sites()
No Hooks.
Return
Int|null
. The site ID, or null if no site is found for the given slug.
Usage
get_id_from_blogname( $slug );
- $slug(string) (required)
- A site's slug.
Examples
#1 Get the network site ID from the name (slug) of the site
Suppose the ID of the desired site is 2, then:
// the site can have the following domain or path, depends on the multisite settings: // blog.site.com // site.com/blog get_id_from_blogname( 'blog' ); //> 2
#2 Switching blogs based on the blogs name ($slug)
$slug = 'another-site'; $id = get_id_from_blogname( $slug ); switch_to_blog( $id ); // Do your staff restore_current_blog();
Changelog
Since 3.0.0 | Introduced. |
Since 4.7.0 | Converted to use get_sites(). |