这是我正在努力使其工作的代码
在这里,我试图拉出所选选项。但这不起作用。每次用户选择某个学生姓名并单击保存按钮时,所选选项将返回为默认选项。
我创建了一个类来将这个下拉菜单插入到主题定制器部分,但它不起作用,我得到了php错误。
我做错了什么?
谢谢你的帮助!
if (class_exists(\'WP_Customize_Control\')):
class Selected_students_Control extends WP_Customize_Control {
global $wpdb;
$query = $wpdb->prepare(\'SELECT * FROM %1$s ORDER BY ID DESC\', \'l7b8z_students\');
$results = $wpdb->get_results($query);
if(!empty($results)) :
$options = \'\';
foreach($results as $result) :
$is_selected = (get_the_title() == $selected) ? \'selected="selected"\' : \'\';
$options.= sprintf("\\t".\'<option value="%1$s $is_selected">%2$s</option>\'."\\n", $result->id, $result->name);
endforeach;
echo \'<select id="my-select" name="my-select">\'."\\n";
echo $options;
echo \'</select>\'."\\n\\n";
endif;
}
endif;
public function customize($customize) {
$customize->add_setting(\'students-admin\', array(
\'default\' => \'Students Admin\',
));
$customize->add_control(new Selected_students_Control
($customize, \'students-admin\', array(
\'label\' => "Select Default ThemeAdmin",
\'section\' => \'footer_section\',
\'settings\' => \'students-admin\',
\'description\' => \'some text\',
\'query\' => array(\'result\' => \'name\')
)));
}