I am trying to save a value into the options using Settings API. The thing is getting saved, but no matter what I do, it always resets the dropdown box. So the saved values are not shown in the drop down box.

I am using var_dump() to show the contents of the Options and it is showing the rpeviously saved values without any problem. Can someone please help me? Here is the screenshot: enter image description here Here is the code:

add_action('admin_init', 'twmm_init');
function twmm_init() {
  register_setting('twmm_options_group', 'twmm_options', 'twmm_options_validation');
  add_settings_section('twmm_setting_section', 'TWMM Settings', 'twmm_section_callback', 'twmm-settings.php');
  add_settings_field('twmm_on_off', 'Enable or disable the maintenance mode here:', 'twmm_status', 'twmm-settings.php', 'twmm_setting_section');
  add_settings_field('twmm_permission_lvl', 'Minimum permission level needed to access the site:', 'twmm_permission', 'twmm-settings.php', 'twmm_setting_section');
function twmm_status() {
  $options = get_option('twmm_options');//check if maintenance mdoe is enabled or disabled
  echo "<select id='twmm_on_off' name='twmm_options[twmm_on_off]'>";
    echo "<option value='Enable'" . selected( $options['twmm_on_off'], 'enabled') . ">Enable</option>";
    echo "<option value='Disable'" . selected( $options['twmm_on_off'], 'disabled') . ">Disable</option>";
  echo "</select>";
function twmm_permission() { //drop down box for user roles
  $options = get_option('twmm_options');
  echo "<select id='twmm_permission_lvl' name='twmm_options[twmm_permission_lvl]'>";
    echo "<option vaule='admin'". selected( $options['twmm_permission_lvl'], 'admin')."> Admin </option>";
    echo "<option vaule='editor'". selected( $options['twmm_permission_lvl'], 'editor')."> Editor </option>";
    echo "<option vaule='author'". selected( $options['twmm_permission_lvl'], 'author')."> Author </option>";
    echo "<option vaule='contributor'". selected( $options['twmm_permission_lvl'], 'contributor')."> Contributor </option>";
    echo "<option vaule='subscriber'". selected( $options['twmm_permission_lvl'], 'subscriber')."> Subscriber </option>";
  echo '</select>';

You are misspelling value to vaule:

echo "<option vaule='editor'". selected( $options['twmm_permission_lvl'], 'editor')."> Editor </option>";

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.