-
Notifications
You must be signed in to change notification settings - Fork 1
Adding meta fields to a meta box
Each meta field is represented by an array, and should be included inside the fields key of the desired metabox. Each field you add to your meta box can accept several keys (arguments).
id - String. Required. The field id. Should be in slug form and must be unique to this field AND to this box. You cannot use the same field id in different boxes. Example: my_field
title - String. Optional. The title for the field's label. Appears to the left of each field. This is what the end user will see.
description - String. Optional A description for the field. Will appear below the actual field.
class - Array. Optional. An array of classes that the field will inherit. Can be used for all field types except wysiwyg.
required - String. Optional. Add this key to make this a required field. The value of this key should be the string to display if the required field was not filled (or was filled incorrectly). The following field types does not support this feature due to it being redundant: radio,select,colorpicker.
sanitize - Array. Optional.An array of sanitation methods the value of the field will pass through before it will be saved. For available sanitation methods, as well as how you can create custom ones, see using sanitation filters and methods.
repeater - Boolean. Optional. Set to TRUE to make this field a repeater.
type - String. Optional. The current field type. The available field types are:
The default field (in case one is not specified) is text. Any illegal field type will be interpreted as a text field. For more information on field types see field types.
Creates a text input. By default it is not sanitized and can contain HTML and code. If you wish to limit a text field to plain text only pass it through the plain_text sanitation filter. The id and class sanitation filters may also come in handy depending on the situation. Example:
array(
'title' => 'Production Studio',
'id' => 'production_studio',
'type' => 'text',
),Creates an email addresses. The field will be validated using PHP and will only accept a valid email address. If you set this field to be a required field it will also be validated as a valid email by the javascript. Example:
array(
'title' => 'Studio Email',
'id' => 'studio_email',
'type' => 'email',
),Creates a text area. Example:
array(
'title' => 'Short Description',
'id' => 'short_description',
'type' => 'textarea',
),Creates a checkbox selector. The checkbox field type requires an additional key called choices. choices is an array that contains the key and value pairs of the checkboxes that will be rendered by this field. Example:
array(
'title' => 'Genres',
'id' => 'movie_genres',
'description' => 'Select the movie genres.',
'type' => 'checkbox',
'choices' => array(
'action' => 'Action',
'comedy' => 'Comedy',
'drama' => 'Drama',
'documentary' => 'Documentary'
),
),Creates a radio selector. The checkbox field type requires an additional key called choices. choices is an array that contains the key and value pairs of the radio buttons that will be rendered by this field. Example:
array(
'title' => 'Released on Blu-ray',
'id' => 'released_on_bd',
'type' => 'radio',
'choices' => array(
'yes' => 'Yes',
'no' => 'No',
),
),Creates a select selector. The select field types requires an additional key called choices. choices is an array that contains the key and value pairs of the select selector that will be rendered by this field. Example:
array(
'title' => 'Good Movie Snack',
'id' => 'movie_snack',
'type' => 'select',
'choices' => array(
'popcorn' => 'Popcorn',
'chocolate' => 'Chocolate',
'none' => 'None',
),
),Creates a colorpicker box. The field will be validated by PHP and will only accept a vaild hex color value. Example:
array(
'title' => 'Movie Page Color',
'id' => 'movie_color',
'description' => 'Select a color that represents this movie.',
'type' => 'colorpicker',
),Creates a file-uploading button. By default the file field type accepts the following formats: jpg,jpeg,png,gif,pdf,txt,docx,xlsx and pptx. To add new formats add the desired format value to the $permittedUploadFormats array property of the Simple_Meta_Boxes class. The file field type can also show a preview image for image type files. It will do so by default for the following formats: jpg,jpeg,png and gif. You can add a new preview-enabled file format by editing the $imageFormats array inside the add_file_image method. Do take note that only image formats that can be rendered natively by the browser can be used. Example:
array(
'title' => 'Movie Poster',
'id' => 'movie_poster',
'type' => 'file',
),Creates a wysiwyg textarea. wysiwyg fields require the corresponding metabox to be seamless and cannot be used as a repeater field or as part of a repeater group. If a wysiwyg field is used incorrectly it will default to an input (in repeater fields) or textarea (all other occasions). The wysiwyg field supports an additional key called args. Args is an array of optional arguments that the field can accept. These arguments are synonymous with those $settings array used by the Wordpress core function wp_editor. Example:
array(
'title' => 'Movie Review',
'id' => 'movie_review',
'type' => 'wysiwyg',
'args' => array(
'media_buttons' => FALSE, //hide the media buttons
),
),