vendredi 27 mars 2015

Select box saves but doesn't update value in admin


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?


Right, I should have pasted the whole code for my meta box at first, but I genuinely thought that it was just this snippet that was causing the problems. You live and learn. Here is my code: http://ift.tt/1OCbsev





Aucun commentaire:

Enregistrer un commentaire