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

Checkbox Field

Arguments

NameTypeDefaultDescription
idstring A unique ID. This ID will be used to get the value
typestringcheckboxType of the 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-corer (as hover/popup) of 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 funciton for sanitizing value
validatestring Callback function for validating value
EXTRAS   
empty_messagestring Display to empty text if options empty
labelstring The text to display with the checkbox, when use to single checkbox
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

query_args Arguments

NameTypeDefaultDescription
post_typestring Custom post type name. Default posts
taxonomystring Custom taxonomy name
posts_per_pagenumber Maximum number of posts to show (Used for Custom Post Types : posts / pages
numbernumber Maximum number of posts to show (used for other returns: categories / tags / menus / ex)
orderbystringpost_titleSort retrieved posts by parameter
orderstringASCDesignates the ascending or descending order of the orderby parameter

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

Basic Checkbox Field Example

array(
  'id' => 'example-checkbox',
  'type' => 'checkbox',
  'title' => 'Example Checkbox',
  'label' => 'Yes, Please Accept',
  'default' => true,  // or false
),

Checkbox Field Example with Multiple Options

array(
  'id' => 'example-checkbox',
  'type' => 'checkbox',
  'title' => 'Checkboxes',
  'options' => array(
    'option1' => 'Option One',
    'option2' => 'Option Two',
    'option3' => 'Option Three',
  ),
  'default' => array('option1','option3),
),

Checkbox Field Example with WP Query Option

array(
  'id' => 'example-checkbox',
  'type' => 'checkbox',
  'title' => 'Checkbox with Categories',
  'options' => 'categories',
  'query_args' => array(
    'orderby' => 'post_title',
    'order' => 'ASC',
  ),
),

/* 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?