Created
November 1, 2012 23:28
-
-
Save themefoundation/3997496 to your computer and use it in GitHub Desktop.
Metabox array for creating metaboxes with the theme toolkit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Defines metabox arrays | |
*/ | |
function thtk_example_metaboxes() { | |
// Defines $prefix. Should begin with an underscore unless you want fields to be doubled in the Custom Fields editor. | |
$prefix = '_example_'; | |
// Defines metabox array. | |
$meta_boxes[] = array( | |
'id' => 'example_metabox', | |
'title' => 'Example Metabox', | |
'post_type' => array( 'page', 'post' ), // Post types to display metabox. | |
'context' => 'normal', // Optional. | |
'priority' => 'high', // Optional. | |
'metabox_fields' => array( | |
array( | |
'id' => $prefix . 'textbox', | |
'title' => 'Text box', | |
'type' => 'text', | |
'description' => 'This is an example text box.', // Optional. | |
'valid' => 'text' // Optional | |
), | |
array( | |
'id' => $prefix . 'textarea', | |
'title' => 'Text area', | |
'type' => 'textarea', | |
'description' => 'This is an example textarea', // Optional. | |
'valid' => 'text' // Optional | |
), | |
array( | |
'id' => $prefix . 'select', | |
'title' => 'Select input', | |
'type' => 'select', | |
'choices' => array('Option 1', 'Option 2', 'test'), | |
'description' => 'This is an example select input', // Optional. | |
// 'valid' property is not available for select lists. | |
// The options listed in the 'options' property are automatically the only valid results. | |
), | |
array( | |
'id' => $prefix . 'radio', | |
'title' => 'Radio input', | |
'type' => 'radio', | |
'choices' => array('Option 3', 'Option 4', 'test'), | |
'description' => 'This is an example radio input', // Optional. | |
// 'valid' property is not available for radio buttons. | |
// The options listed in the 'options' property are automatically the only valid results. | |
), | |
array( | |
'id' => $prefix . 'multicheck', | |
'title' => 'Multiple checkbox input', | |
'type' => 'multicheck', | |
'choices' => array( // $id => $label for each checkbox | |
$prefix . 'check_one' => 'Option 23', | |
$prefix . 'check_two' => 'Option 34', | |
$prefix . 'check_three' => 'test' | |
), | |
'description' => 'This is an example checkbox input', // Optional. | |
// 'valid' property is not available for multicheck. | |
// See explanation in "checkbox" section above. | |
), | |
) // End array metabox_fields | |
); // End array $meta_boxes | |
$meta_boxes[] = array( | |
'id' => 'another_metabox', | |
'title' => 'Another Metabox', | |
'post_type' => array( 'post' ), // Post types to display metabox. | |
'metabox_fields' => array( | |
array( | |
'id' => $prefix . 'another', | |
'title' => 'Another example', | |
'type' => 'text', | |
), | |
) // End array metabox_fields | |
); // End array $meta_boxes | |
// Add other metaboxes here as needed. | |
return $meta_boxes; | |
} | |
add_filter( 'thtk_metaboxes_filter', 'thtk_example_metaboxes' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment