WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
can you show the code? – Bainternet Jun 29 '11 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 '11 at 18:59
How does the select field look like? Does it have the same name field as the option name? – onetrickpony Jun 30 '11 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 '11 at 14:03
up vote 1 down vote accepted

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

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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