I have a select dropdown in my custom meta box in the admin area. It offers two options Approved and In Progress. When I select an option and save it the database is updated, but the value in the admin area is not. What I see is the first item from the list displayed in the select box. i.e. if I select In Progress and save the admin shows Approved as the selected value even though it is saved as In Progress in the database and displays In Progress on the front end of the site.
Here is my code:
<label for="myplugin_meta_box_select">Status:</label> <select name="myplugin_meta_box_select" id="myplugin_meta_box_select"> <option value="Approved" <?php selected( $selected, 'approved' ); ?>>Approved</option> <option value="In Progress" <?php selected( $selected, 'inprogress' ); ?>>In Progress</option> </select>
And I save it with this:
if( isset( $_POST['myplugin_meta_box_select'] ) ) update_post_meta( $post_id, 'myplugin_meta_box_select', esc_attr( $_POST['myplugin_meta_box_select'] ) );
What have I missed out?