[CMB Metabox并选择下拉菜单

问题描述 投票:0回答:2

我在CMB metabox上遇到问题,然后选择下拉菜单。例如,如果我的选择框包含数组Banana,Orange,Apple,那么我只能看到价值的第一个字母,它在admin和网站(前端)中仅打印第一个字母。什么会导致该问题?

        array(
'name'    => 'Test Radio',
'id'      => $prefix . 'test_radio',
'type'    => 'radio',
'options' => array(
    'standard' => __( 'Banana', 'cmb' ),
    'custom'   => __( 'Orange', 'cmb' ),
    'none'     => __( 'Apple', 'cmb' ),
),
),
wordpress meta-boxes
2个回答
2
投票

我有同样的问题。这对我有用:

array(
    'name'    => 'Test Select',
    'id'      => $prefix . 'test_select',
    'type'    => 'select',
    'options' => array(
        array(
            'name'  => __( 'Banana', 'cmb' ),
            'value' => 'banana',
        ),
        array(
            'name'  => __( 'Orange', 'cmb' ),
            'value' => 'orange',
        ),
        array(
            'name'  => __( 'Apple', 'cmb' ),
            'value' => 'apple',
        ),
    ),
),

1
投票

您正在使用单选类型字段,需要选择类型字段。试试这个:

array(
'name'    => 'Test Select',
'id'      => $prefix . 'test_select',
'type'    => 'select',
'options' => array(
    'banana'    => __( 'Banana', 'cmb' ),
    'orange'    => __( 'Orange', 'cmb' ),
    'apple'     => __( 'Apple', 'cmb' ),
    ),
),

0
投票

有人发现问题了吗?

我有同样的问题:我尝试使用@Jacopo Fernandez解决方案,但效果不佳,因为我只能填充选择的“值”,而不能填充html。the html valuesthe frontend

感谢您的帮助!

© www.soinside.com 2019 - 2024. All rights reserved.