I was reading wordpress theme handbook , They said

 $wp_customize->add_setting( 'myplugin_options[color]', array(
'type' => 'option',
'capability' => 'manage_options',
'default' => '#ff2525',
'sanitize_callback' => 'sanitize_hex_color',
) );

Note that the Customizer can handle options stored as keyed arrays for settings using the option type. This allows multiple settings to be stored in a single option that isn’t a theme mod. To retrieve and use the values of your Customizer options, use get_theme_mod() and get_option() with the setting id:

I tried.

 $wp_customize->add_setting('options[toggle_hedaer]',array('default'=>true,'type'=>'option','capability' => 'manage_options','transport' => 'postMessage'));
 $wp_customize->add_control('options[toggle_header]',array('section' => 'live_options','label'=>'Display header?','type'=>'checkbox'));
 $wp_customize->add_setting('options[background]',array('default' => 'normal','type'=>'option','capability'=>'manage_options','transport' => 'postMessage'));
 $wp_customize->add_control('options[background]',array('section'=>'live_options','label'=> 'Change Background','type'=>'radio','choices'=>array('normal'=>'Normal','inverse'=>'Inverse') ));

But it does not create any option in database, Can someone explain what i am doing wrong ? and what is the right method to store multiple setting in single option ?

1 Answer 1


In your example here, the option stored would be named options and it would contain two array keys, toggle_header and background. To obtain the values, then, you would do:

$options = get_option( 'options', array() );
$options = array_merge( array( 'toggle_hedaer' => true, 'background' => 'normal' ), $options );

// Accessing stored values here:
$toggle_header = $options['toggle_hedaer'];
$background = $options['background'];

Naturally you should choose an ID base for the setting to be different from “options”.

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.