I'm having an interesting problem that I can't seem to solve.

While creating a widget, I have created a select field with options that can be chosen on the widget screen. It all works perfectly fine, except when I save the widget, all of the options in the select field vanish. They all come back, with my chosen option saved, as soon as I refresh.

The code for each of the select options looks like this:

foreach ($posttypes as $option) { echo '<option id="' . $option->name . '"', $posttype == $option->name ? ' selected="selected"' : '', '>', $option->name, '</option>'; }

In this case, $posttypes is an array of post types.

When the select fields are rendered, they look like this:

<select name="option-name" id="option-name"> <option value="option-value">Option Value</option> <option value="option-value">Option Value</option> <option value="option-value">Option Value</option> </select>

Any ideas why they would vanish like this?

  • can you show the code?
    – Bainternet
    Jun 29, 2011 at 18:56
  • My select options look like this: foreach ($posttypes as $option) { echo '<option id="' . $option->name . '"', $posttype == $option->name ? ' selected="selected"' : '', '>', $option->name, '</option>'; }
    – Pippin
    Jun 29, 2011 at 18:59
  • How does the select field look like? Does it have the same name field as the option name? Jun 30, 2011 at 0:29
  • Once rendered, the select form looks like this: <select name="option-name" id="option-name"><option value="option-value">Option Value</option><option value="option-value">Option Value</option><option value="option-value">Option Value</option></select>
    – Pippin
    Jun 30, 2011 at 14:03

1 Answer 1


Found it. There was an extra closing slash on the opening select field.

  • just add the same annoying problem, and your answer got me looking for the same thing which solved it +1
    – Bainternet
    Aug 8, 2011 at 21:38
  • Glad to know I'm not the only one afflicted with blindness ;)
    – Pippin
    Aug 9, 2011 at 1:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.