为选择wordpress php添加选项

为选择wordpress php添加选项,php,html,wordpress,Php,Html,Wordpress,我用的是主题:马达 我想为管理面板添加带有选项的选择。 选项应为:“-”、“eletro”、“auto” 我已经添加了select,但它是空的: $manager->register_control( 'autofilling', array( 'type' => 'select', 'section' => 'stm_options', 'preview' =>

我用的是主题:马达 我想为管理面板添加带有选项的选择。 选项应为:
“-”、“eletro”、“auto”
我已经添加了select,但它是空的:

    $manager->register_control(
        'autofilling',
        array(
            'type' => 'select',
            'section' => 'stm_options',
            'preview' => 'autofilling',
            'label' => esc_html__( 'Autofilling', 'stm_vehicles_listing' ),
            'attr' => array( 'class' => 'widefat' )
        )
    );
我试着写
'options'=>“['-','eletro','auto']”,
,但没有成功。 我还尝试:

 'options' => [
                    '-' => __( '-', 'stm_vehicles_listing' ),
                    'electro' => __( 'electro', 'stm_vehicles_listing' ),
                    'auto' => __( 'auto', 'stm_vehicles_listing' ),
                ],
以及:


也许我可以用DB添加它们?但是怎么做呢?

试试这段代码。您需要使用
选项
而不是
选项

$manager->register_control(
    'autofilling',
    array(
        'type' => 'select',
        'section' => 'stm_options',
        'preview' => 'autofilling',
        'label' => esc_html__( 'Autofilling', 'stm_vehicles_listing' ),
        'attr' => array( 'class' => 'widefat' ),
        'choices' => array(
            'default' => __( '-', 'stm_vehicles_listing' ),
            'electro' => __( 'electro', 'stm_vehicles_listing' ),
            'auto' => __( 'auto', 'stm_vehicles_listing' ),
        ),
    )
);

谢谢。我想你的回答会帮助很多人,因为我在互联网上找不到任何东西,我的同事也不知道怎么做!很高兴帮助您@Alex.:)您在默认选项中获得了
x
,BTW@Alex,答案已更新。您知道如何添加onchange吗?
$manager->register_control(
    'autofilling',
    array(
        'type' => 'select',
        'section' => 'stm_options',
        'preview' => 'autofilling',
        'label' => esc_html__( 'Autofilling', 'stm_vehicles_listing' ),
        'attr' => array( 'class' => 'widefat' ),
        'choices' => array(
            'default' => __( '-', 'stm_vehicles_listing' ),
            'electro' => __( 'electro', 'stm_vehicles_listing' ),
            'auto' => __( 'auto', 'stm_vehicles_listing' ),
        ),
    )
);