-
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. Repeater fields don't work inside repeater groups.
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 the field types section.
default - String/Array. Optional. The default value for this field. Notes:
- Defaults cannot be specified for the select field type.
- Colopickers should have their default color provided with the hashtag sign. Example:
#359337 - All field type defaults should be provided as strings, except for the checkbox field defaults which should be provided as an array.
- Simple Meta Boxes will revert to the default option if a field is empty and if that field is saved with an empty string ('') as its value. If you wish to save an empty string instead of the default value either remove the default property key, change the default property to an empty string or input a string with a single backspace (' ') in the field before saving it.
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 input. The field will be validated on the server side using PHP and will only accept a valid email address. On the client side HTML5 supported browsers will validate the email upon trying to submit the page. Furthermore, If you set this field to be a required field the email will also be validated by the Simple Meta Boxes' JavaScript field validation class. 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 media-uploading button. Clicking on this button will open the Wordpress media uploader and allow users to view, select, upload and delete files. The type of files that can be uploaded depend on Wordpress' own restrictions and the degree to which users can use the media uploader is subject to their user privileges. Example:
array(
'title' => 'Movie Poster',
'id' => 'movie_poster',
'type' => 'media',
),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 Revenues (Excel Spreadsheet)',
'id' => 'movie_revenues',
'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
),
),