Build an elementor widget that uses CPT categories

94 Views Asked by At

Good morning I'm building a custom Elementor (free) widget to display a masonry gallery on the site. I need a way to load the category list for my custom post type called "opera".

I'm currently listing all categories manually, like that

$this->add_control(
        'opera_category',
        [
            'label' => __( 'Opera category', 'mydomain' ),
            'type' => \Elementor\Controls_Manager::SELECT,
            'options' => [
                '10' => __( 'category A', 'mydomain' ),
                '12' => __( 'category B', 'mydomain' ),
                '14' => __( 'category C', 'mydomain' ),
            ],
            'default' => '',
        ]
    );

It works, but it forces me to update the widget code every time a new category is added.

Is there a way to load the category list? Some javascript, I suppose... Or maybe there's a way to pass some params when I register the widget.

Thanks!

0

There are 0 best solutions below