Elementor widgets - conditional controls

I'm creating my first elementor widget. I need to create 3 conditional controls: Select a (custom)post_type ->

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',
            ]
        );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745179396a4615349.html

相关推荐

  • Elementor widgets - conditional controls

    I'm creating my first elementor widget. I need to create 3 conditional controls: Select a (custom)post_type ->

    3小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信