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