我正在尝试创建一个自定义 Wordpress 小部件,它有一个下拉选择和文本输入字段。一切正常,但是当我返回小部件(例如编辑)时,选择下拉列表始终显示顶部结果而不是我的选择。
// 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']); ?>
<br /><br />
<label>Choose an icon:</label>
<select id="<?php echo $this->get_field_id('posttype'); ?>" name="<?php echo $this->get_field_name('posttype'); ?>" class="widefat" style="width:100%;">
<option <?php selected( $instance['posttype'], 'Briefcase Icon'); ?> …Run Code Online (Sandbox Code Playgroud)