On the widget settings for a slider plugin I'm writing I have a combo box that is populated with registered post types (allowing the user to select which post type they want to display images from), a combo box that's populated with image sizes (either default or ones added via add_image_size();), and a text box that allows the user to enter in the number of images to display. The problem is the form ignores the saved post type and displays the 1st in the combo box. For example, 'posts' is the first item in the combo box. If a user selects 'pages' and saves the form, the value is saved and the slider pulls the 'pages' post type on the front end, but the back end displays 'posts' as the selected item in the drop down. This issue does not affect the image size combo box.
<select id="<?php echo $this->get_field_id( 'post_type' ); ?>" name="<?php echo $this->get_field_name( 'post_type' ); ?>">
<?php
$types = get_post_types( '', 'names' );
foreach( $types as $type )
echo '<option value=' . esc_attr( $type ) . '" ' . selected( $type, $instance['post_type'], FALSE ) . '>' . esc_html( $type ) . '</option>';
?>
</select>
The image combo box code is such
<select id="<?php echo $this->get_field_id( 'image_size' ); ?>" name="<?php echo $this->get_field_name( 'image_size' ); ?>">
<?php
$sizes = arconix_get_image_sizes();
foreach( (array) $sizes as $name => $size )
echo '<option value="' . esc_attr( $name ) . '" ' . selected( $name, $instance['image_size'], FALSE ) . '>' . esc_html( $name ).' ( ' . $size['width'] . 'x' . $size['height'] . ' )</option>';
?>
</select>
Any suggestions as to what I'm doing wrong?