Select Option

LPH

Well-known member
I'm working on a pull-down select option. The options show but once chosen and saved then the values return to the default.

Code:
$filterOptions = array('latest', 'unread', 'watched');

?>
    <p>
        <label for="<?php echo $this->get_field_id( 'filter' ); ?>">Type of posts:</label>
        <select id="<?php echo $this->get_field_id( 'filter' ); ?>"
                name="<?php echo $this->get_field_name( 'filter' ); ?>">
        
        <?php foreach ( $filterOptions as $filterItem ) {
                echo '<option value="' . $filterOptions . '"';
                if ( $filterItem == $instance['filter'] ) {
                      echo ' selected="selected"';
                }
               echo '>' . $filterItem . '</option>';
                } ?>
        </select>
    </p>

Does anyone see anything obviously wrong that I'm doing? I have similar code in another widget and everything saves.
 
This line is incorrect. Ugh

Code:
echo '<option value="' . $filterOptions . '"';

Should be
Code:
echo '<option value="' . $filterItem . '"';

Maybe this will help others. Wasted hour :p
 
Back
Top Bottom