title: Wordpress php how to add and save the values of a select dropdown to custom post type
body: <p>I have created a custom post typ ewithin wordpress called "actors"</p>
  
  <p>In this custom post type, I have added some metaboxes where the admin can add custom data about each actor.</p>
  
  <p>I need one of these metaboxes to be a select input rather than a text input, however I can't figure out how to make the value save, and show as selected.</p>
  
  <p>Here is my current php code:</p>
  
  <pre><code>// Add the Actors Meta Boxes
  function add_actor_metaboxes() {
      add_meta_box('actors_info', 'Actor Info', 'Nial_Actors::actors_info', 'actors', 'normal', 'default');
  }
  
  // The Actors Metabox
  function actors_info() {
      global $post;
  
      // Noncename needed to verify where the data originated
      echo '&lt;input type="hidden" name="actorinfometa_noncename" id="actorinfometa_noncename" value="' . 
      wp_create_nonce( plugin_basename(__FILE__) ) . '" /&gt;';
  
      // Get the location data if its already been entered
      $spotlight_url = get_post_meta($post-&gt;ID, '_spotlight_url', true);
      $actor_gender = get_post_meta($post-&gt;ID, '_actor_gender', true);
      $actor_age = get_post_meta($post-&gt;ID, '_actor_age', true);
      $actor_height = get_post_meta($post-&gt;ID, '_actor_height', true);
      $actor_weight = get_post_meta($post-&gt;ID, '_actor_weight', true);
  
      // Echo out the field
      echo '&lt;p&gt;Spotlight URL&lt;/p&gt;';
      echo '&lt;input type="text" name="_spotlight_url" value="' . $spotlight_url  . '" class="widefat" /&gt;';
      echo '&lt;p&gt;Gender&lt;/p&gt;';
  
      echo '&lt;select name="_actor_gender" id="actor_gender"&gt;';
      echo    '&lt;option value="null" ' . selected( $actor_gender, 'null' ) . '&gt;--&lt;/option&gt;';
      echo    '&lt;option value="male" ' . selected( $actor_gender, 'male' ) . '&gt;Male&lt;/option&gt;';
      echo    '&lt;option value="female" ' . selected( $actor_gender, 'female' ) . '&gt;Female&lt;/option&gt;';
      echo '&lt;/select&gt;';
  
      echo '&lt;p&gt;Age&lt;/p&gt;';
          echo '&lt;input type="text" name="_actor_age" value="' . $actor_age  . '" class="widefat" /&gt;';
      echo '&lt;p&gt;Height&lt;/p&gt;';
          echo '&lt;input type="text" name="_actor_height" value="' . $actor_height  . '" class="widefat" /&gt;';
      echo '&lt;p&gt;Weight&lt;/p&gt;';
          echo '&lt;input type="text" name="_actor_weight" value="' . $actor_weight  . '" class="widefat" /&gt;';
  
  }
  
  // Save the Metabox Data
  function actor_info_save($post_id, $post) {
  
      // verify this came from the our screen and with proper authorization,
      // because save_post can be triggered at other times
      if ( !isset($_POST['actorinfometa_noncename']) || !wp_verify_nonce( $_POST['actorinfometa_noncename'], basename(__FILE__) )) {
          return $post-&gt;ID;
  
      }
      //if ( !wp_verify_nonce( $_POST['actorinfometa_noncename'], plugin_basename(__FILE__) )) {
      //return $post-&gt;ID;
      //}
  
      // Is the user allowed to edit the post or page?
      if ( !current_user_can( 'edit_post', $post-&gt;ID ))
          return $post-&gt;ID;
  
      // OK, we're authenticated: we need to find and save the data
      // We'll put it into an array to make it easier to loop though.
  
      $actor_meta['_spotlight_url'] = $_POST['_spotlight_url'];
      $actor_meta['_actor_gender'] = $_POST['_actor_gender'];
      $actor_meta['_actor_age'] = $_POST['_actor_age'];
      $actor_meta['_actor_height'] = $_POST['_actor_height'];
      $actor_meta['_actor_weight'] = $_POST['_actor_weight'];
  
      // Add values of $actor_meta as custom fields
  
      foreach ($actor_meta as $key =&gt; $value) { // Cycle through the $actor_meta array!
          if( $post-&gt;post_type == 'revision' ) return; // Don't store custom data twice
          $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
          if(get_post_meta($post-&gt;ID, $key, FALSE)) { // If the custom field already has a value
              update_post_meta($post-&gt;ID, $key, $value);
          } else { // If the custom field doesn't have a value
              add_post_meta($post-&gt;ID, $key, $value);
          }
          if(!$value) delete_post_meta($post-&gt;ID, $key); // Delete if blank
      }
  
  }
  </code></pre>
  
  <p>Is there something obvious I am missing here - I want the "Gender" option to be a dropdown select input</p>