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 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>
share|improve this question
On a side note, this code begs for a loop to keep things DRY. – Geert Feb 10 '12 at 8:05

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/selected

Without you pasting more of your code I cannot see how to fix your above code.

share|improve this answer
I don't think so. If you look into the code of this function, you'll see that the 3rd parameter is "echo" which is a boolean value. – Rilwis Nov 2 '11 at 13:43
Yup you are right but the codex at the time of posting this answer the codex wasn't showing the echo parameter. codex.wordpress.org/Function_Reference/… notice the codex entry was updated in August... – Brady Nov 2 '11 at 13:55

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.