-
Notifications
You must be signed in to change notification settings - Fork 124
Create a Meta Box
Tarei King edited this page Feb 5, 2016
·
15 revisions
To add your own meta boxes, use the 'cmb_meta_boxes' filter to add your own meta box to the array of meta boxes.
Each meta box can be created by passing an array of setting. See available arguments listed below.
- id (string) (optional) HTML 'id' attribute of the meta box. Constructed from title, if omitted.
- title (string) (required) Title of the edit screen section, visible to user
- fields (array) (required) An array of fields that will be added to the meta box.
- pages (string/array) (required) The type of Write screen on which to show the meta box (eg 'post', 'page', 'attachment'). Also accepts an array of post types.
-
show_on (array) (optional) Further restrict where a meta box is shown. An array of key => value where key is what you are restricting by. Available restrictions are
id
andpage-template
. ID expects a numeric value or array of values. Page Template expects a string; the filename of the template. - hide_on (array) (optional) Same as show_on, but allows you to hide by page template or post ID.
- context (string) (optional) The part of the page where the edit screen section should be shown ('normal', 'advanced', or 'side'). Default: 'advanced'
- priority (string) (optional) The priority within the context where the boxes should show ('high', 'core', 'default' or 'low')
- desc (string) (optional) Meta box description. Displayed as first item in meta box, above fields.
add_filter( 'cmb_meta_boxes', 'cmb_sample_metaboxes' );
function cmb_sample_metaboxes( array $meta_boxes ) {
$meta_boxes[] = array(
'title' => 'CMB Test - all fields',
'pages' => 'page',
'show_on' => array( 'id' => array( 1 ) ),
'hide_on' => array( 'page-template' => array( 'test-page-template.php' ) ),
'context' => 'normal',
'priority' => 'high',
'fields' => $fields // an array of fields - see individual field documentation.
'desc' => 'This is the meta box description.',
);
return $meta_boxes;
}
- Setup/Install Custom Meta Boxes
- Creating a custom meta box
- Displaying Field Data
- Optional Generic Field Args
- Repeatable Fields
General
- Text Field
- Small Text Field
- Number Field
- URL Field
- Textarea Field
- Code Field
- Select Field
- Checkbox Input Field
- Radio Input Field
Date & Time
WordPress
Media
Utilities