Table of Contents
A dropdown select field for choosing one or multiple options from a list.
Example Usage #
sample-plugin.php
// Single Select Example
array(
'id' => 'notification_method',
'title' => 'Notification Method',
'desc' => 'Choose how notifications should be delivered',
'type' => 'select',
'options' => array(
'email' => 'Email',
'sms' => 'SMS',
'push' => 'Push Notification',
),
'placeholder' => 'Select method',
'default' => 'email',
'value' => get_option( 'notification_method' ),
),
// Multiple Select Example
array(
'id' => 'allowed_roles',
'title' => 'Allowed User Roles',
'desc' => 'Select which user roles can access the system',
'type' => 'select',
'options' => array(
'administrator' => 'Administrator',
'editor' => 'Editor',
'author' => 'Author',
),
'placeholder' => 'Select user roles',
'multiple' => true,
'default' => array( 'administrator', 'editor' ),
'value' => get_option( 'allowed_roles' ),
),
Properties #
- id (required) – Unique identifier for the field
- title (required) – Label displayed above the select field
- desc (optional) – Help text shown below the field
- type (required) – Must be
'select' - options (required) – Associative array of
value => labelpairs - placeholder (optional) – Placeholder text shown when no selection is made
- multiple (optional) – Set to
trueto allow multiple selections (default:false) - default (optional) – Default value (string for single, array for multiple)
- value (optional) – Current saved value(s)
Notes #
When multiple is enabled, the field returns an array of selected values. For single select, it returns a string.