0

I have a Meta box with two user inputs 1: Text-field and 2:a Select drop Down options. I used following Save Method in mt Meta box and second part of the code belong to saving the Selected option from drop down.

function save_options(){
global $post;
if (!isset($_POST['price']) || $post->post_type != 'product')
{
    return $post;
}
update_post_meta($post->ID, "price", $_POST['price']);

if (!isset($_POST['nyc_borough']) || $post->post_type != 'product')
{
    return $post;
}
update_post_meta($post->ID, "nyc_borough", $_POST['nyc_borough']);
}

Everything works fine so far an I am even able to retrieve the selected value in a custom Column, however when I go to Edit Product session the Drop down options always shows the first Item selected( As Default). So I have to update the select box again otherwise it is going to select the first Item and update the metadata! Can you please let me know why this is happening and how I can prevent it?

Thanks for you time and comments

  • 1
    Have you seen this? – fuxia May 19 '13 at 19:11
  • As the thread @toscho is linking to is saying (sort of), you need to check what option has been chosen and then have php print "selected" in the option tag that has been chosen. – Richard B May 19 '13 at 19:14
  • Hi toscho, Richard Thanks for your comments I tried to use the Selected() in my code as your recommended link explained it but it didn't' go through! Please be informed that I have no problem with saving and displaying the options meta on WP. My problem in fact is displaying the SELECTED item in Edit session. As the First input "price" correctly display the saved value but the second option(the Select input) is just displaying the first index from the array! – Behseini May 20 '13 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.