WordPress-从wpdb响应创建定制器对象

所以我有以下代码:

add_action('customize_register', 'homepage_sections'); //products function homepage_sections($wp_customize){ $wp_customize-> add_panel('homepage_sections', array( 'title'=> 'Homepage Sections', 'priority'=> '20' )); $wp_customize-> add_section('homepage_settings_section', array( 'title'=> 'Homepage settings', 'panel'=> 'homepage_sections', )); $wp_customize-> add_setting('homepage_settings_setting', array( 'default'=> 1 )); $wp_customize-> add_control('homepage_settings_control', array( 'section'=> 'homepage_settings_section', 'settings'=> 'homepage_settings_setting', 'label'=> 'Number of sections', 'description'=> 'Number of sections in homepage', 'type'=> 'number' )); global $wpdb; $sections=$wpdb-> get_results('SELECT section_id, section_title FROM vt_homepage_sections; '); foreach($sections as $key){ $section_id=$key-> section_id; $cust_setting_id=$section_id.'_setting'; $cust_control_id=$section_id.'_control'; $wp_customize-> add_setting($cust_setting_id, array()); $wp_customize-> add_control($cust_control_id, array( 'settings'=> $cust_setting_id, 'section'=> 'homepage_settings_section', 'label'=> 'test Control' )); } }

【WordPress-从wpdb响应创建定制器对象】问题当我不使用包含使用$ wpdb获取的值的变量时, 一切工作正常。是否在定制程序框架之后加载$ wpdb对象?
当我使用上面的代码时, 以上自定义对象的字体会出现在定制器面板中。希望能得到有关我上面的代码有什么问题的提示。
提前致谢,
?
#1请像这样尝试:’ $ sections = $ wpdb-> get_results(‘ SELECT section_id, section_title FROM vt_homepage_sections’ ); ’
#2在函数开始时定义全局类并检查。

    推荐阅读