Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

closed as too localized by toscho Feb 17 at 22:54

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

On line 5 of the problem code I didn't provide the opening " for the $type where I'm setting the option. Details, details, details.

share|improve this answer

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