使用WordPress设置API创建的刷新选项?
我正在开发一个特定于主题的插件来处理主题的大部分功能。我有几个设置页面,其中有几个按主要类别创建选项。例如,设置页面具有上载每个父类别的横幅图像以在该类别的存档页面上使用的选项。基本代码如下所示:使用WordPress设置API创建的刷新选项?,wordpress,Wordpress,我正在开发一个特定于主题的插件来处理主题的大部分功能。我有几个设置页面,其中有几个按主要类别创建选项。例如,设置页面具有上载每个父类别的横幅图像以在该类别的存档页面上使用的选项。基本代码如下所示: public static function option_fields() { $prefix = 'otw_category_banner_'; $categories = get_categories( 'parent=0' ); // Only need to init
public static function option_fields() {
$prefix = 'otw_category_banner_';
$categories = get_categories( 'parent=0' );
// Only need to initiate the array once per page-load
if ( ! empty( self::$theme_options ) )
return self::$theme_options;
$fields = array();
foreach ( $categories as $category ) {
$fields[] = array(
'name' => __( $category->name, 'cmb' ),
'id' => $prefix . $category->term_id,
'type' => 'file',
'allow' => array( 'url', 'attachment' ) // limit to just attachments with array( 'attachment' )
);
}
self::$theme_options = array(
'id' => 'theme_options',
'show_on' => array( 'key' => 'options-page', 'value' => array( self::$key, ), ),
'show_names' => true,
'fields' => $fields,
);
return self::$theme_options;
}
这段代码最初运行良好,但在创建初始选项后,它似乎不会在添加新的父类别时更新。我是一名新手开发人员,也是第一次发布海报,因此任何帮助都将不胜感激。我是一个白痴……发现问题后,get_categories()只返回至少附带一篇帖子的类别。添加“hide_empty=0”修复了该问题。