0

I have a multisite network with around 30 sites on it.

In the wp_sitemeta table, there are some options the previous dev had set (one of which is 'template_color').

So in the wp_sitemeta table, there is a site_id with a meta_key of 'template_color', and a meta_value of the hex value of the color.

I've written the following:

    foreach ( $sites as $site ) {
            switch_to_blog( $site->blog_id );
            //do things
            $value = get_site_option( 'template_color', 'not available' );
            echo $value;
            restore_current_blog();

    }

But $value just shows 'not available' for each site.

Am I doing something incorrectly?

2

The documentation for this is contradictory, but I believe wp_sitemeta is meant to only store information for sites in the wp_sites table, which only stores the main site in a network. It would make more sense to store each site's template_color in their individual wp_[BLOGID]_options tables.

However, keeping the data as-is, you may be able to use the following instead of get_site_option:

get_network_option( $site->blog_id, 'template_color', 'not_available' )
  • The 1st parameter in get_network_option() is the $network_id, not the $blog_id, so unfortunately I don't think this will work. – Pat J May 22 '18 at 21:10
  • 1
    I agree it's not supposed to work, but the reason it would is because the previous dev was storing the subsites' blog IDs in a database column that WP expects the network ID to be stored in. The get_site_option function is just a wrapper of get_network_option. I got it to work after manually adding a row in the wp_sitemeta table. Still, it's a hack, and I'd recommend moving the template_color values to individual wp_options tables. – SeventhSteel May 22 '18 at 22:04
  • 1
    What I forgot is that this is a multi-network, multi-site install. get_network_option() is what I needed and it worked. – Hanny May 23 '18 at 11:41
  • I'm glad you found a solution. Please update your question to include the multi-network aspect—it'll help others who might be having a similar problem. – Pat J May 23 '18 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.