29. Multiselect

'multiselect' => array(
    'type' => 'multiselect',
    'label' => esc_html__( 'Multiselect', 'my-domain' ),
    'options' => array(
        array(
            'label' => 'My super title 1',
            //You can add any data you need to save as key => value
        ),
        array(
            'label' => 'My super title 2',
        ),
    )
),

If you have same elements in one list of options, you have to add unique selector and specify it in config under key track_by

'multiselect_2' => array(
    'type' => 'multiselect',
    'label' => esc_html__( 'Multiselect', 'my-domain' ),
    'options' => array(
        array(
            'label' => 'My super title 1',
            'value' => '1'
        ),
        array(
            'label' => 'My super title 1',
            'value' => '2'
        ),
    ),
    'track_by' => 'value'
),

Last updated