我正在使用Kirki,并试图为自定义分类法中的每个术语生成一个切换(以便在以后的主题中为每个术语添加显示/隐藏帖子的功能):
function generate_toggles() {
$months = get_terms( array(\'months\') );
foreach ($months as $month) :
Kirki::add_field( \'mytheme\', array(
\'type\' => \'toggle\',
\'settings\' => $month->slug,
\'label\' => __( \'Июль\', \'my_textdomain\' ),
\'section\' => \'months\',
\'default\' => \'1\',
\'priority\' => 10,
));
endforeach;
}
add_action(\'???\', \'generate_toggles\', 9999);
但我不明白的是,我应该将动作附加到哪里?既然我想让它出现在Kirki小组中,那么我应该把它附加到哪个行动上?
最合适的回答,由SO网友:Runnick 整理而成
您可以使用Kirki helper类来实现这一点(将您的分类传递到Kirki_Helper::get_terms), 但您需要在注册分类法后进行注册,否则会出现错误:
function my_theme_add_categories_customizer_control() {
Kirki::add_field(\'my_config\', array(
\'type\' => \'multicheck\',
\'settings\' => \'show_months\',
\'label\' => esc_attr__(\'My Control\', \'my_textdomain\'),
\'section\' => \'months\',
\'priority\' => 10,
\'choices\' => Kirki_Helper::get_terms(array(\'months\'))
));
}
add_action( \'init\', \'my_theme_add_categories_customizer_control\', 12 );