Dynamic data as option value for Elementor controls

Viewed 1102

I'm doing a custom Elementor Widget(in Wordpress) and I'm trying to get a Select control to have as options the data from another control. This is my code

 $property_types = array(
            'type1_slug'=>'type1_label',
            'type2_slug'=>'type2_label',
            'type3_slug'=>'type3_label',
            'type4_slug'=>'type4_label',
            'type5_slug'=>'type5_label',
        );

$this->add_control(
                'type_data',
                [
                    'label'     => esc_html__( 'Select Types', 'elementor' ),
                    'type'      => Controls_Manager::SELECT2,
                    'options'   => $property_types,
                    'description' => '',
                    'multiple' => true,
                    'label_block' => true,
                    'default' => '',
                   
                ]
            );
///////// a repeater is defined....

$repeater = new Repeater();
$repeater->add_control(
                'tab_holder', [
                    'label' => esc_html__('select Tabs', 'elementor'),
                    'type' => Controls_Manager::SELECT,
                    'options' => '' ,
                    'default' => 'type1_slug',
                ]
        );

What I'm trying to do is to have as options in "tab_holder" the values i selected in "type_data". Thank you

1 Answers

This code get the taxonomy like category from the database and show in Elementor select2 control. Show Dynamic dropdown.

 $categories = get_categories();
   $items = array();
   foreach( $categories as $category ) {
    $items[] = $category->name;
   }
    $this->add_control(
          'show_category',
          [
            'label' => __( 'Category', 'plugin-domain' ),
            'type' => \Elementor\Controls_Manager::SELECT2,
            'multiple' => true,
            'options' => $items,
            'default' => [],
          ]
        );
Related