1. Home
  2. Docs
  3. WordPress Studio Framework
  4. Framework Fields
  5. Select Field

Select Field

Arguments

NameTypeDefaultDescription
idstring A unique ID. This ID will be used to get the value
typestringselectType of field
titlestring Title of the field
defaultarray|string Default value from database, if the option doesn’t exist
subtitlestring Subtitle to display below the title
descstring Description to display after the field
helpstring Text to display on right-corner (as hover/popup) the field
classstring Extra CSS classes (space separated) to append to the field
beforestring Content to display before the field
afterstring Content to display after the field
dependencyarray Define field visibility depending on other field value
attributesarray Extra HTML attributes to append to the field
sanitizestring Callback function for sanitizing value
validatestring Callback function for validating value
EXTRAS   
empty_messagestring Display to empty text if options empty
placeholderstring The placeholder to be displayed when nothing is selected
chosenboolfalseFlag to enable ChosenJS style select
multipleboolfalseFlag to allow multiple options choice
sortableboolfalseFlag to allow sortable options choice
ajaxboolfalseFlag to allow ajax search options choice
optionsarray|string An array of object containing key/value pairs representing the options or use a predefined options (pages posts categories tags menus users sidebars roles post_types)
query_argsarray An associative array of query arguments. Using with (pages posts categories tags menus)
settingsarray An associative array containing arguments for the chosen setting

Query_Args Arguments

NameTypeDefaultDescription
post_typestring Custom post type name
taxonomystring Custom taxonomy name
posts_per_pagenumber Maximum number of posts to show (for post types)
numbernumber Maximum number of posts to show (for taxonomies)
orderbystringpost_titleSort retrieved posts by parameter
orderstringASCDesignates the ascending or descending order of the orderby parameter (ASC | DESC)

Get more query arguments for (posts,pages: wp_query) and (categories, tags, menus: wp_term_query)

Settings Arguments

NameTypeDefaultDescription
min_lengthnumber3Minimum search input length for trigger ajax search
widthstringautoChosen style width
typing_textstringPlease enter %s or more charactersChosen ajax typing text
searching_textstringSearching…Chosen ajax searching text
no_results_textstringNo results matchChosen ajax no results text

Simple Select Field Example

array(
  'id' => 'example-select',
  'type' => 'select',
  'title' => 'Example Select',
  'placeholder' => 'Select an option',
  'options' => array(
    'opt1' => 'Option One',
    'opt2' => 'Option Two',
    'opt3' => 'Option Three',
  ),
  'default' => 'opt3',
),

Select Field Example with Groups

array(
  'id' => 'example-select',
  'type' => 'select',
  'title' => 'Example Select',
  'placeholder' => 'Select an option',
  'options' => array(
    'Group 1' => array(
      'opt1' => 'Option One',
      'opt2' => 'Option Two',
      'opt3' => 'Option Three',
    ),
    'Group 2' => array(
      'opt4' => 'Option Four',
      'opt5' => 'Option Five',
      'opt6' => 'Option Six',
    ),
  ),
  'default' => array('opt3','opt6'),
),

Select Field Example with Chosen

array(
  'id' => 'example-select',
  'type' => 'select',
  'title' => 'Example Select',
  'chosen' => true,
  'placeholder' => 'Select an option',
  'options' => array(
    'opt1' => 'Option One',
    'opt2' => 'Option Two',
    'opt3' => 'Option Three',
    'opt4' => 'Option Four',
    'opt5' => 'Option Five',
    'opt6' => 'Option Six',
  ),
  'default' => 'opt3',
),

Select Field Example with Multiple Chosen

array(
  'id' => 'example-select',
  'type' => 'select',
  'title' => 'Example Select',
  'chosen' => true,
  'multiple' => true,
  'placeholder' => 'Select an option',
  'options' => array(
    'opt1' => 'Option One',
    'opt2' => 'Option Two',
    'opt3' => 'Option Three',
    'opt4' => 'Option Four',
    'opt5' => 'Option Five',
    'opt6' => 'Option Six',
  ),
  'default' => array('opt3','opt4'),
),

Select Field Example with Chosen AJAX Search

//Select with AJAX search Pages
array(
  'id' => 'example-select',
  'type' => 'select',
  'title' => 'Select with pages',
  'placeholder' => 'Select a page',
  'chosen' => true,
  'ajax' => true,
  'options' => 'pages',
),

//Select with multiple and sortable AJAX search Posts
array(
  'id' => 'example-select-2',
  'type' => 'select',
  'title' => 'Select with posts',
  'placeholder' => 'Select posts',
  'chosen' => true,
  'ajax' => true,
  'multiple' => true,
  'sortable' => true,
  'options' => 'posts',
),

//Select with multiple and sortable AJAX search Categories
array(
  'id' => 'example-select-3',
  'type' => 'select',
  'title' => 'Select with categories',
  'placeholder' => 'Select categories',
  'chosen' => true,
  'ajax' => true,
  'multiple' => true,
  'sortable' => true,
  'options' => 'categories',
),

//Select with AJAX search CPT
array(
  'id' => 'example-select-4',
  'type' => 'select',
  'title' => 'Select CPT',
  'placeholder' => 'Select a post',
  'chosen' => true,
  'ajax' => true,
  'options' => 'posts',
  'query_args' => array(
    'post_type' => 'post_type_name',
  ),
),

//Select with AJAX search CPT Categories
array(
  'id' => 'example-select-5',
  'type' => 'select',
  'title' => 'Select with CPT categories',
  'placeholder' => 'Select a category',
  'chosen' => true,
  'ajax' => true,
  'options' => 'categories',
  'query_args' => array(
    'taxonomy' => 'your_taxonomy_name',
  ),
),

/* Available Options
* 'options' => 'pages',
* 'options' => 'posts',
* 'options' => 'categories',
* 'options' => 'tags',
* 'options' => 'menus',
* 'options' => 'users',
* 'options' => 'sidebars',
* 'options' => 'roles',
* 'options' => 'post_types',
*/
Was this article helpful to you? Yes No

How can we help?