Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

For some reason, this (found herehere) works. However, I still haven't managed to adapt it to do what I want to do. Therefore, this answers only partially my question.

<select id="<?php echo $this->get_field_id('posttype'); ?>" name="<?php echo $this->get_field_name('posttype'); ?>" class="widefat" style="width:100%;">
  <?php foreach(get_post_types($getposttype_args,'names') as $post_type) { ?>
    <option <?php selected( $instance['posttype'], $post_type ); ?> value="<?php echo $post_type; ?>"><?php echo $post_type; ?></option>
  <?php } ?>      
</select>

For some reason, this (found here) works. However, I still haven't managed to adapt it to do what I want to do. Therefore, this answers only partially my question.

<select id="<?php echo $this->get_field_id('posttype'); ?>" name="<?php echo $this->get_field_name('posttype'); ?>" class="widefat" style="width:100%;">
  <?php foreach(get_post_types($getposttype_args,'names') as $post_type) { ?>
    <option <?php selected( $instance['posttype'], $post_type ); ?> value="<?php echo $post_type; ?>"><?php echo $post_type; ?></option>
  <?php } ?>      
</select>

For some reason, this (found here) works. However, I still haven't managed to adapt it to do what I want to do. Therefore, this answers only partially my question.

<select id="<?php echo $this->get_field_id('posttype'); ?>" name="<?php echo $this->get_field_name('posttype'); ?>" class="widefat" style="width:100%;">
  <?php foreach(get_post_types($getposttype_args,'names') as $post_type) { ?>
    <option <?php selected( $instance['posttype'], $post_type ); ?> value="<?php echo $post_type; ?>"><?php echo $post_type; ?></option>
  <?php } ?>      
</select>
Source Link
Macxim
  • 123
  • 2
  • 9

For some reason, this (found here) works. However, I still haven't managed to adapt it to do what I want to do. Therefore, this answers only partially my question.

<select id="<?php echo $this->get_field_id('posttype'); ?>" name="<?php echo $this->get_field_name('posttype'); ?>" class="widefat" style="width:100%;">
  <?php foreach(get_post_types($getposttype_args,'names') as $post_type) { ?>
    <option <?php selected( $instance['posttype'], $post_type ); ?> value="<?php echo $post_type; ?>"><?php echo $post_type; ?></option>
  <?php } ?>      
</select>