1

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>
1
  • On a side note, this code begs for a loop to keep things DRY.
    – Geert
    Feb 10, 2012 at 8:05

1 Answer 1

1

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.

2
  • 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.
    – Anh Tran
    Nov 2, 2011 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...
    – Scott
    Nov 2, 2011 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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