I wanted to update custom blog option created thru Settings Api using the function update_blog_option. I created this code.

    $country_base = get_blog_option($blog_id, 'mytheme_options');//retrieve all options
    $country_base['country_base'] = $the_country;
    $currency_unit = get_blog_option($blog_id, 'mytheme_options');//retrieve all options
    $currency_unit['currency_unit'] = $d_currency;

    update_blog_option($blog_id, 'mytheme_options', $country_base);
    update_blog_option($blog_id, 'mytheme_options', $currency_unit);

However, its not working.. Is there way to update custom blog option?


As per the Codex on update_blog_option:

Switches to the blog id specified, runs update_option() and then restores to the current blog. If $refresh is true then it will refresh the blog details.

Not tested, but I think your problem is trying to update elements of the array instead of the whole thing:

$the_options = get_blog_option($blog_id, 'mytheme_options');//retrieve all options

$the_options['country_base'] = $the_country;
$the_options['currency_unit'] = $d_currency;

update_blog_option($blog_id, 'mytheme_options', $the_options);

I think it's best just to switch_to_blog($id); and use regular functions as add_option(), get_option(), update_option(). When you're done you'd better use restore_current_blog(); to switch back.

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.