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?
foreach ($posttypes as $option) { echo '<option id="' . $option->name . '"', $posttype == $option->name ? ' selected="selected"' : '', '>', $option->name, '</option>'; }
name
field as the option name?<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>