0

I'm working on a WPMU plugin that cycles through tables in each blog on the network. I can't use get_option to pull the settings array out of the wp_n_options tables, so I'm trying to do it by querying $wpdb and then using unserialize().

I know the query is successful because I can print_r result, but it's wrapped in an array, and I can't figure out how to just get the serialized string out of it.

Any pointers?

---EDIT---

What it's actually returning is this: stdClass Object ( [option_value] => ~serialized string~ )

2
  • Have you tried and use switch_to_blog and get_option together to get this to work? Dec 17, 2013 at 9:42
  • 1
    Put this as answer so I can mark it. Thanks a bundle. Wasn't familiar with the switch_to_blog function. Dec 17, 2013 at 9:48

1 Answer 1

0

You can use the following two inbuilt functions to do this.

  1. switch_to_blog
  2. get_option

You can use both in the following way to make a function out of it which would give you the option. Put the below in the functions.php file

function wpse_get_options( $blog_id = 1 ){
    switch_to_blog( $blog_id );

    $get_option = get_option( $option ); // Replace $option with the option name
    restore_current_blog(); // Switch back to the original blog

    return $get_option;
}

Now you can use the above function to fetch the options by using the function and passing the blog id/ sub site id.

$options = wpse_get_options( $blog_id );
// Replace the $blog_id with blog id of your sub sites.

Your Answer

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

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