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.

I'm storing all my options using Settings API:

function registerSettings() {

register_setting('XX_theme_settings', 'XX_theme_settings', 'setting_validate' );

add_settings_section('theme_options', 'Theme Options', 'theme_options_generate', 'page1' ); 
add_settings_field( 'XX_Option1', 'Option 1', 'text_input', 'page1', 'theme_options', 'XX_Option1' );
add_settings_field( 'XX_Option2', 'Option 2', 'text_input', 'page1', 'theme_options', 'XX_Option2' ); 

};

add_action('admin_init', 'registerSettings');

Let's say I want to update XX_Option2 manually (not using forms, but via PHP), how should I do that?

I was thinking about update_option('XX_theme_settings[XX_Option2]', value), but that doesn't work (?).

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

That's because your options are stored as a serialised array, in one row with name XX_theme_settings. To update one option, you would still need to retrieve the existing settings, ammend the appropriate value and update all options in your array together.

For example:

$my_options= get_option('XX_theme_settings');//retrieve all options
$my_options['XX_Option2'] = 'my new value'; //amend value in array(s)
update_option('XX_theme_settings', $my_options); //update option array
share|improve this answer
    
Hey, @StephenHarris, you might want to take look at this question (it's almost the same, I want to update multiple options at once this time): wordpress.stackexchange.com/questions/120567/… –  Wordpressor Oct 29 '13 at 22:56
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.