I’m trying to put in a simple dropdown menu in my widget. I copied one out of a previous widget and trying to substitute my own values into it. The submenu shows, but when I click save, it saves only the first selection (design 1). Actually, I echoed the value on the widget and all of the options displayed.
What would a simple widget drop down menu look like?
As for my code, I think I need to get that “true” out of there and replace it with Design#
<label for="<?php echo $this->get_field_id('fold_design'); ?>"><?php _e('Display style:'); ?></label>
<select id="<?php echo $this->get_field_id('fold_design'); ?>" name="<?php echo $this->get_field_name('fold_design'); ?>" class="widefat" />
<option <?php selected( 'Design1', $instance['fold_design'], true ); ?>>Design 1</option>
<option <?php selected( 'Design2', $instance['fold_design'], true ); ?>>Design 2</option>
<option <?php selected( 'Design3', $instance['fold_design'], true ); ?>>Design 3</option>
<option <?php selected( 'Design4', $instance['fold_design'], true ); ?>>Design 4</option>
<option <?php selected( 'Design5', $instance['fold_design'], true ); ?>>Design 5</option>
<option <?php selected( 'Design6', $instance['fold_design'], true ); ?>>Design 6</option>
<option <?php selected( 'Design7', $instance['fold_design'], true ); ?>>Design 7</option>
</select>
The format of the
selected()
function you are using is incorrect.selected()
can only be passed two variables, you are passing three. Please see this codex article for help: http://codex.wordpress.org/Function_Reference/selectedWithout you pasting more of your code I cannot see how to fix your above code.