title: Wordpress widget <select> not displaying when saved
body: <p>I'm attempting to create a custom Wordpress Widget, that has a dropdown select and text input field. Everything works, however when I go back to the widget (for example to edit) the select dropdown always displays the top result instead of my selection.</p>
  
  <pre><code>// New Text and Icon Widget
  class Image_Picker extends WP_Widget {
  
      /** constructor -- name this the same as the class above */
      function Image_Picker() {
      parent::WP_Widget(false, $name = 'Homepage Column Text and Icon Select');   
    } 
  
    function form($instance) {
        //WIDGET BACK-END SETTINGS
            $message  = $instance['message'];
            $posttype = $instance['posttype'];
           // $posttype = esc_attr($instance['posttype']);  ?&gt;
  
        &lt;br /&gt;&lt;br /&gt;
  
        &lt;label&gt;Choose an icon:&lt;/label&gt;
        &lt;select id="&lt;?php echo $this-&gt;get_field_id('posttype'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('posttype'); ?&gt;" class="widefat" style="width:100%;"&gt; 
  
  
          &lt;option &lt;?php selected( $instance['posttype'], 'Briefcase Icon'); ?&gt; value="briefcase"&gt;Briefcase Icon&lt;/option&gt; 
          &lt;option &lt;?php selected( $instance['posttype'], 'Chat Icon'); ?&gt; value="chat"&gt;Chat Icon&lt;/option&gt; 
          &lt;option &lt;?php selected( $instance['posttype'], 'Document Icon'); ?&gt; value="document"&gt;Document Icon&lt;/option&gt; 
          &lt;option &lt;?php selected( $instance['posttype'], 'Firstaid Icon'); ?&gt; value="firstaid"&gt;Firstaid Icon&lt;/option&gt; 
          &lt;option &lt;?php selected( $instance['posttype'], 'Form Icon'); ?&gt; value="form"&gt;Form Icon&lt;/option&gt; 
          &lt;option &lt;?php selected( $instance['posttype'], 'Graph Icon'); ?&gt; value="graph"&gt;Graph Icon&lt;/option&gt; 
          &lt;option &lt;?php selected( $instance['posttype'], 'Healthcare Icon'); ?&gt; value="healthcare"&gt;Healthcare Icon&lt;/option&gt;
          &lt;option &lt;?php selected( $instance['posttype'], 'Heart Icon'); ?&gt; value="heart"&gt;Heart Icon&lt;/option&gt; 
          &lt;option &lt;?php selected( $instance['posttype'], 'Image Icon'); ?&gt; value="image"&gt;Image Icon&lt;/option&gt;
          &lt;option &lt;?php selected( $instance['posttype'], 'Leaves Icon'); ?&gt; value="leaves"&gt;Leaves Icon&lt;/option&gt; 
          &lt;option &lt;?php selected( $instance['posttype'], 'Mail Icon'); ?&gt; value="mail"&gt;Mail Icon&lt;/option&gt;  
          &lt;option &lt;?php selected( $instance['posttype'], 'Mobile Icon'); ?&gt; value="mobile"&gt;Mobile Icon&lt;/option&gt; 
          &lt;option &lt;?php selected( $instance['posttype'], 'People Icon'); ?&gt; value="people"&gt;People Icon&lt;/option&gt;
          &lt;option &lt;?php selected( $instance['posttype'], 'Screen Icon'); ?&gt; value="screen"&gt;Screen Icon&lt;/option&gt;
          &lt;option &lt;?php selected( $instance['posttype'], 'Stats icon'); ?&gt; value="stats"&gt;Stats icon&lt;/option&gt;  
          &lt;option &lt;?php selected( $instance['posttype'], 'Video Icon'); ?&gt; value="video"&gt;Video Icon&lt;/option&gt; 
      &lt;/select&gt;
  
        &lt;br /&gt;&lt;br /&gt;
        &lt;label for="&lt;?php echo $this-&gt;get_field_id('message'); ?&gt;"&gt;&lt;?php _e('Text:'); ?&gt;&lt;/label&gt; 
            &lt;input class="widefat" id="&lt;?php echo $this-&gt;get_field_id('message'); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name('message'); ?&gt;" type="text" value="&lt;?php echo $message; ?&gt;" /&gt;
  
            &lt;br /&gt;&lt;br /&gt;
  
        &lt;?php
        } 
  
    function update($new_instance, $old_instance) {
        global $posttypes;
        $instance['message'] = strip_tags($new_instance['message']);
        $instance['posttype'] = $new_instance['posttype'];
        return $instance;
    }
  
  
    function widget($args, $instance) {
        extract( $args );
        $message  = $instance['message'];
        $posttype = $instance['posttype']; 
  
          echo ' &lt;li class="item_content clearfix"&gt;&lt;a class="features_image" href="#" title=""&gt;
          &lt;img src="';
          echo bloginfo('template_url');
          echo '/assets/images/features_large/';
          echo $posttype;
          echo '.png" alt="" /&gt;
          &lt;/a&gt; &lt;div class="text"&gt;';
          echo '' . $message . '&lt;div class="item_footer clearfix"&gt;
              &lt;a title="Read more" href="about.html" class="more"&gt;Read more &amp;rarr;&lt;/a&gt;
          &lt;/div&gt;&lt;/div&gt;&lt;/li&gt;'; 
  
    }
  }
  
  // Add class for Random Posts Widget
  add_action( 'widgets_init', create_function('', 'return register_widget("Image_Picker");') );
  </code></pre>
  
  <p>Any help is very much appreciated.</p>