Are blog and site two different things? Apologies if this question seems basic, but when referring to a WordPress website, I've always used both terms very loosely (to mean the same thing). I'm now wondering if there is a difference?
get_option() returns an option for the current blog.
In single site installation, the current blog is the only blog. So get
get_option() returns the option for it.
get_site_option() is used to retrieve an option network-wide. It means that you can get the same option from any site of the network.
When this function is used in single installation, it normally returns the same thing of
get_option(). The value may change because
get_site_option() trigger filter hooks that are not triggered by
Note that once the
$wpdb->options table is blog-specific, network-wide options are stored in the
$wpdb->sitemeta table, that is specific of multisite installations.
get_blog_option() is the only among the three functions that doesn't receive the option name as 1st argument, but its 1st argument is
In fact, it is used in multisite installations to retrieve an option from a specific blog whose the id is known.
What this function does is:
switch_to_blog( $blog_id ); $value = get_option( $option, $default ); restore_current_blog(); return $value;
$blog_id is the same of current blog id, WordPress just skips the
switch_to_blog part and just calls
This function is defined in the file
wp-includes/ms-blogs.php that is loaded only for multisite installation, so
get_blog_option() is not defined in single site installations.
get_site_option() - Gets a network wide option. This option is usually added in the Network Admin Settings section of a multisite set-up. If I had 50 sites, it would be a pain to go to 50 different sites and set the same option value. Instead I could set the option value once and have it apply across the network for all sites. See http://codex.wordpress.org/Function_Reference/get_site_option
get_blog_option() - Lets you get the value of an option for a specific site. One example might be to get the value of a user specific option for each site. So I could get all of the sites that the user belongs too, loop over the list of site IDs, and use
get_blog_option() passing the
blog_id and option name and get back the result. It's a convenience function that pretty much does the following:
switch_to_blog( $id );
$value = get_option( $option_name );
get_site_option() gets a network wide value,
get_blog_option() gets a specific value for a given site without needing to switch to that site first on your own.