Documentation: “Meta Boxes” File Structure

To create a meta box, create a php file, and drop it in the meta-boxes folder. Any fields added to this file will be grouped in the same meta box. Meta box attributes can be defined in the comment block at the top of the file… no coding required!

 

Comment block attributes

title
Name of meta box. Will appear in the meta box as <h3>. You can include HTML in this field if you want.
example: My Meta Box
example with HTML: My Meta Box  <span class=”alignright”>Check out these fields</span>

description
A description of your meta box. This field doesn’t do anything except add a description for you.

post type
The post type that will show this meta box.
values: ‘post’, ‘page’, ‘link’, or ‘custom_post_type’ where custom_post_type is the custom post type slug
default: none

capability
User capability that can view this meta box. This is not the “minimum” capability, this is the actual capability. Do not include if you wish to allow all users to view. (coming soon: the ability to add an array of capabilities). ** Do not use with “role”. Use one or the other.
example: ‘manage_options’
default: whatever is set in register_post_type

role
User role that can view this meta box. This is not the “minimum” role, this is the actual role . Do not include if you wish to allow all users to view. (coming soon: the ability to add an array of roles). ** Do not use with “capability”. Use one or the other.
example: ‘administrator’

ID
The ID of the Post/Page you want this meta box to display.
example: ‘ID: 2′

context
The part of the page where the edit screen section should be shown.
values: ‘normal’, ‘advanced’, or ‘side’
default: ‘advanced’

priority
The priority within the context where the boxes should show
values: ‘high’, ‘core’, ‘default’ or ‘low’
default: ‘default’

order
The sort order of the meta box, within the context and priority. Allows for creating an absolute order of meta boxes.  NOTE: If the “lock” attribute is not set, or set to “false”, then the order you set is the default. The user can still drag and drop the meta boxes and take them out of your designated order.
example: 1, 2, 3, etc
default: none

status
List of post statuses that will show this meta box. No space between each status. Remember, Piklist allows for custom post statuses.
example: published,prequote,repair-quote
default: all

lock
Locking the meta box stops the user from being able to drag it around the edit screen.
value: ‘true’, ‘false’
default: ‘false’

new
Show this meta box when creating a new post.
value: ‘true’, ‘false’
default: true

collapse
If set to true, this meta box will be collapsed by default
value: ‘true’,'false’
default: ‘false’

 

Example code:

<?php
/*
Title: My Meta Box
Description: My cool new meta box
Post Type: my_post_type
Capability: manage_options
Context: normal
Priority: high
Order: 1
Status: published,prequote,repair-quote
Locked: true
New: false
Collapse: true
*/

// Let's create a text box field
 piklist('field', array(
   'type' => 'text'
   ,'scope' => 'post_meta'
   ,'field' => 'field_name'
   ,'label' => __('Example Field')
   ,'description' => __('Field Description')
   ,'attributes' => array(
     'class' => 'text'
   )
   ,'position' => 'wrap'
 ));
 ?>