【发布时间】:2017-07-16 14:57:54
【问题描述】:
我正在使用Wordpress Settings API。除了这个select 下拉菜单外,一切都正常工作。当我选择一个选项时,回显的值是正确的,但在下拉列表中它显示默认的第一个值,即6,而不是选定的值。我哪里错了?
public function someplugin_select() {
$options = get_option( 'plugin_252calc');
echo $options; //shows the correct value selected
$items = array();
for ($i=6; $i <=10; $i+= 0.1)
{
$items[] = $i;
}
echo '<select id="cf-nb" name="cf-nb">';
foreach ( $items as $item )
{
echo '<option value="'. $item .'"';
if ( $item == $options ) echo' selected="selected"';
echo '>'. $item .'</option>';
}
echo '</select>';
}
【问题讨论】: