Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way I can access the wp_options table of all the child sites? I want to create a multisite plugin that can be setup at the network level and will populate the child site plugins with defaults that can then be overwritten by the each individual site. I'm aware that I could read/write from wp_sitemeta this way, but in my instance, it would make sense if I could access the other "local" tables. I could probably write a custom query using the WP query function, but I was wondering if there was a better way?

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

Try get_blog_option(). It does not use switch_to_blog(), and so introduces much less overhead. https://codex.wordpress.org/Function_Reference/get_blog_option

share|improve this answer
    
Is there a function for writing options, too? And is there a function for retrieving all ID's for all sites? –  NightHawk Mar 29 '12 at 19:57
    
update_blog_option(). I don't think there's a WP function for getting all site ids. Try: global $wpdb; $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs" ) ); –  Boone Gorges Mar 29 '12 at 20:48
    
Gotcha. Thanks for your help! –  NightHawk Mar 29 '12 at 22:07
add comment

Try switch_to_blog and restore_current_blog.

Both functions are quite expensive, you may wish to implement only small parts of their functionality, like changing the prefix of $wpdb.

http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/ms-blogs.php

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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