Strange multisite issue where all sites return same id with get_current_site()

admin2025-04-21  0

I'm trying to add some code based on which multisite is shown. However for both the main site and sub-domains it always shows the ID as 1. I've put

$current_site = get_current_site();
var_dump($current_site);

in both the header.php and index.php and they both output the same for every sub-domain:

object(WP_Network)[275]
  private 'id' => int 1
  public 'domain' => string '...' (length=16)
  public 'path' => string '/' (length=1)
  private 'blog_id' => int 1
  public 'cookie_domain' => string '...' (length=16)
  public 'site_name' => string '...' (length=19)

Has anyone else ran into this issue and know of a way to get the correct current id?

I'm trying to add some code based on which multisite is shown. However for both the main site and sub-domains it always shows the ID as 1. I've put

$current_site = get_current_site();
var_dump($current_site);

in both the header.php and index.php and they both output the same for every sub-domain:

object(WP_Network)[275]
  private 'id' => int 1
  public 'domain' => string '...' (length=16)
  public 'path' => string '/' (length=1)
  private 'blog_id' => int 1
  public 'cookie_domain' => string '...' (length=16)
  public 'site_name' => string '...' (length=19)

Has anyone else ran into this issue and know of a way to get the correct current id?

Share Improve this question edited Sep 9, 2019 at 19:46 Alex asked Sep 9, 2019 at 19:40 AlexAlex 1621 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

When Multisite was first rolled into core (from a project call "multi-user", which is why you'll sometimes see references to "mu-*"), the terminology was that you'd run a site of blogs. Now we refer to a network of sites, but because the functions had all already been named, get_current_site() gets the current network.

You'll need to use get_current_blog_id() to get the current site's ID, or get_bloginfo() or get_blog_details() for more detailed data on the current site.

Reference

  • Note on get_current_site
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745172055a288716.html

最新回复(0)