gpt4 book ai didi

wordpress - 动态数据作为 Elementor 控件的选项值

转载 作者:行者123 更新时间:2023-12-05 05:56:43 26 4
gpt4 key购买 nike

我正在做一个自定义 Elementor Widget(在 Wordpress 中),我正在尝试让一个 Select 控件将来自另一个控件的数据作为选项。这是我的代码

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

我想做的是将我在“type_data”中选择的值作为“tab_holder”中的选项。谢谢

最佳答案

此代码从数据库中获取分类法,如类别,并显示在 Elementor select2 控件中。显示动态下拉菜单。

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

关于wordpress - 动态数据作为 Elementor 控件的选项值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69085032/

26 4 0
文章推荐: kubernetes - 当 kubectl 将生命周期修补到容器时,请求无效
文章推荐: html - 用户选择时