-
Notifications
You must be signed in to change notification settings - Fork 142
Field example: Select
Ralf Wiechers edited this page Nov 17, 2016
·
4 revisions
Here's how you can use a select
field with pre-populated options within the registration of your Shortcode UI.
array(
'label' => 'Field Label',
'description' => 'Description shown below the field. HTML tags possible.',
'attr' => 'yourshortcodeattribute',
'type' => 'select',
'options' => array(
'value1' => 'Label 1',
'value2' => 'Label 2',
'value3' => 'Label 3',
),
),
If you're using select
for number range, you can shorten the 'options'
value:
array(
'label' => __( 'Number of Items', 'your-text-domain' ),
'attr' => 'items',
'type' => 'select',
'options' => array_combine( range( 1, 7 ), range( 1, 7 ) ),
'multiple' => false,
),
produces:
<select name="items" id="shortcode-ui-items-c300" placeholder="">
<option value="1" selected="">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>