4

Hey there I am pretty confused on how to store network wide options within a WordPress multisite installation.

The usual way to store any settings in WordPress is:

add_option();
update_option();
delete_option();

However the wp_options table is created for each site within a multisite installation.

The following tables are subsite specific:

myprefix_siteid_commentmeta          
myprefix_siteid_comments             
myprefix_siteid_links                
myprefix_siteid_options              
myprefix_siteid_postmeta             
myprefix_siteid_posts                
myprefix_siteid_term_relationships   
myprefix_siteid_term_taxonomy        
myprefix_siteid_termmeta             
myprefix_siteid_terms                

The following tables are network wide:

myprefix_blogs // multisite specific
myprefix_blog_versions // multisite specific
myprefix_registration_log // multisite specific
myprefix_signups // multisite specific
myprefix_site // multisite specific
myprefix_sitemeta // multisite specific
myprefix_users
myprefix_usermeta

Do you see the problem? There is no adequate table for storing options for the whole network, which sucks in my opinion.

However I assume that you store network wide options in the base wp_options table (myprefix_options). However I cannot use add_option() and update_option() and so on without using switch_to_blog(1) before.

Is there a better possibility? If not, how can I get the base wp_options table prefix?

3
  • 1
    will let someone else answer, but a nitpick, it is a "network" wide option you want to understand as a multisite may have several networks, global option will be something totally different. Aug 7, 2018 at 13:09
  • @MarkKaplun Sure what I mean in my question was network wide options. I know networks of networks are upcoming (and partly implemented), but thats another dimension. Though it would be interesting how to store global options (for many networks), too.
    – Blackbam
    Aug 7, 2018 at 13:46

1 Answer 1

5

There are functions for saving and retrieving network-wide options:

add_network_option();

update_network_option();

get_network_option();

The values of these options are stored in wp_sitemeta.

3
  • Ah this is the correct location. The site id is zero and therefore the option is for the whole network, thanks.
    – Blackbam
    Aug 7, 2018 at 13:41
  • For site (=network of blogs) options get_site_option() is used.
    – Blackbam
    Aug 7, 2018 at 14:30
  • 1
    get_site_option() is just a wrapper for get_network_option(). *_network_option is the terminology since 4.4. Aug 7, 2018 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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