Get_option use inside switch select option

I try to make inside theme custom admin panel a switch select option. but i cannot get the value of switch case. following is my code:

$  bannerchange = $  _POST['bannerchange'];  if( get_option('bannerchange') != get_option($  bannerchange)) {             $  bannerchange = update_option( 'bannerchange', get_option($  bannerchange));  }  <?php if(isset($  _POST['wphw_submit']) && $  chk):?>   <div id="message" class="updated below-h2">     <p>Content updated successfully</p>   </div>     <?php endif;?>       <form method="post" action="">  <select name="wphw_submit" onchange="this.form.submit()">      <option value="page1"<?php if ($  bannerchange == "page1") { echo " selected"; } ?>>Custom Departure</option>      <option value="page2"<?php if ($  bannerchange  == "page2") { echo " selected"; } ?>>Fixed Departure</option> </select> <noscript><input type="submit" value="Submit"></noscript>  </div> <input type="submit" name="wphw_submit" value="Save changes" class="button-primary" /> <?php  switch ($  bannerchange) {     case 'page2': ?>                  <p>two</p>          <?php         break;     case 'page1':         ?>         <p>one</p>         <?php         break;     }     ?> 

$ bannerchange get always undefined.

Settings API: Setting default option via ‘get_option’ fails

  1. All my options are stored in one array test_hs_options
  2. I have select list settings field ( test_hs_options['duration_months'] ) which stores the selected month (1-12).
  3. For this settings field, I would like to set a default option at 5.
  4. All my attempts at setting the default have failed.
  5. What am I missing?
// Callback for displaying sfield_select_duration. function cb_test_hs_sfield_select_duration() {      // get option test_hs_options['duration_months'] value from db.     // Set to '5' as default if option does not exist.     $  options  = get_option( 'test_hs_options', [ 'duration_months' => '5' ] );      $  duration = $  options['duration_months']; // fails!      var_dump($  options); // PHP Notice:  Undefined index: duration_months      // define the select option values for 'duration' select field.     $  months = array( '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12' );      // Display select control     echo '<select id="duration" name="test_hs_options[duration_months]">';         // loop through option values         foreach ( $  months as $  month ) {             // if saved option matches the option value, select it.             echo '<option value="' . $  month . '" ' . selected( $  duration, $  month, false ) . '>' . esc_html( $  month ) . '</option>';         }     echo '</select>'; }  

WordPress Plugin Development – get_option error

I am trying to put the option on selected with the built in function of wordpress called selected. I have tried to change the key from opt to different key names for every select field and it still didn’t work.

At the moment i am stuck, see my code below:

$  taxonomy_args = array(     'public'    =>  true,     '_builtin'  =>  false );  $  taxonomy_names = get_taxonomies($  taxonomy_args);  $  select_field = get_option('select_field');   echo "<form id='example_details' method='post' action''>";     foreach( $  taxonomy_names as $  taxonomy_name ) {         echo "<div class='div_fields'>";         $  taxonomy_name_lc = strtolower($  taxonomy_name);         echo "<label for='$  {taxonomy_name_lc}_select_field'>$  {taxonomy_name}</label>";             echo "<select class='example_form_select' name='details_select_field[opt]' id='$  {taxonomy_name_lc}_select_field'>";                 echo "<option></option>";                 $  terms = get_terms( array(                      'hide_empty'    => false,                     'taxonomy'      => $  taxonomy_name                 ) );                                  foreach ($  terms as $  term) {                     echo "<option id='" . $  term->name . "' value='" . $  term->name . "' " . selected(isset($  select_field['opt']), $  term->name) . ">" . $  term->name . "</option>";                 }               echo "</select>";         echo "</div>";     }     wp_nonce_field( $  this->plugin, 'details_nonce' ); echo "</form>";  

I did a var_dump on the $ select_field variable but that one returns a boolean of false.