For WordPress Multisite, I needed a function that worked like get_option(). So here's a simple one I wrote.
[php]function get_ms_option($blogID, $option_name) {
global $wpdb;
$select_statement = "SELECT *
FROM `".DB_NAME."`.`".$wpdb->get_blog_prefix($blogID)."options`
WHERE `option_name` LIKE '".$option_name."'";
$sql = $wpdb->prepare($select_statement);
$option_value = $wpdb->get_results( $sql, ARRAY_A );
return $option_value[0]['option_value'];
}
[/php]
Another option is to use $wpdb->get_var (thanks to Kawauso from #WordPress IRC):
[php]function get_ms_option($blogID, $option_name) {
global $wpdb;
$select_statement = "SELECT *
FROM `".DB_NAME."`.`".$wpdb->get_blog_prefix($blogID)."options`
WHERE `option_name` LIKE '".$option_name."'";
$sql = $wpdb->prepare($select_statement);
$option_value = $wpdb->get_var( $sql, 3 );
return $option_value;
}
[/php]
clyde says
Hi there, two little questions.
First does the get_ms_option() function loops through all blogs in a MS installation?
Second is 🙁 I simple cant get it to work, i need to pull out a field from every blog option table and store it in a variable…
but all i get is nothing.
Is there a way you can send me a query that pulls something out of the option table?
Thank you best wishes …. clyde
Travis Smith says
Hello Clyde,
This function pulls one option from one site. One approach you could take with this code is to cycle through all available sites/blogs (helpful code) and then use this to build the array. However, you’d be better off talking with Andrea or Ron on the StudioPress forums as they live and breath WordPress Multisite and Genesis.
Thanks,
Travis
Akin Williams says
A useful function. Thanks for sharing it!