Widget development – Drop down options won’t save

Danny, this is pretty much lifted straight from a plug-in I’ve made:

 <?php function form($instance){    
    $instance = wp_parse_args( (array) $instance, $this->w_arg );
  ?>
  <p>
    <select id="<?php echo $this->get_field_id('order'); ?>" name="<?php echo $this->get_field_name('order'); ?>" type="text">
        <option value="asc" <?php selected($instance['order'], 'asc'); ?>>ASC </option>
        <option value="desc" <?php selected($instance['order'], 'desc');?>>DESC </option>
    </select>
</p>

<?php
  }
?>

Without seeing the rest of your code I can’t be sure the root of the problem, but it could be the form is not wrapped inside the form function. If the above doesn’t seem to work for you, perhaps pastie your Widget Class?

I should perhaps add that my widget class has a variable w_arg, an array of defaults! E.g.

var $w_arg = array(
        'order'=> 'ASC'
        );

Leave a Comment