最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Elementor widgets - conditional controls

programmeradmin2浏览0评论

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',
            ]
        );
发布评论

评论列表(0)

  1. 暂无评论