admin管理员组文章数量:1415491
I'm creating my first elementor widget. I need to create 3 conditional controls: Select a (custom)post_type -> select a taxonomy belonging to the respective post_type -> select posts belonging to the respective taxonomy.
How can I create these controlls?
This is what I got untill now, but the problem is, that when I choose a post type, in the taxonomy list I have all the taxonomies, not only those belonging to the chosen post_type.
$post_types = get_post_types([], 'objects');
$options = [];
foreach ( $post_types as $post_type ) {
$options[$post_type->name] = $post_type->label;
}
$this->add_control(
'post_types',
[
'label' => __( 'Choose a post type', 'cf-elementor-apm-widget' ),
'type' => \Elementor\Controls_Manager::SELECT,
'options' => $options,
'classes' => 'post_types',
]
);
$taxonomies = get_taxonomies([], 'objects');
$options = [];
foreach ( $taxonomies as $taxonomy ) {
$options[$taxonomy->name] = $taxonomy->label . " [{$taxonomy->name}]";
}
$this->add_control(
'taxonomies',
[
'label' => __( 'Choose a taxonomy', 'cf-elementor-apm-widget' ),
'type' => \Elementor\Controls_Manager::SELECT,
'options' => $options,
'classes' => 'taxonomy',
]
);
本文标签: Elementor widgetsconditional controls
版权声明:本文标题:Elementor widgets - conditional controls 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745179396a2646396.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论