-
Notifications
You must be signed in to change notification settings - Fork 566
Examples
If you didn't know, the example-functions.php contains examples for how to use CMB2 in many different contexts, including registering fields for many different object types:
-
Non-post post-types. in this case, the "Page" post-type, limited to the page with the id of
2. - User profile pages
- Taxonomy terms
- Options Page
- Comment-edit page
Add fields to the comment-edit page:
add_action( 'cmb2_admin_init', 'yourprefix_register_comment_metabox' );
/**
* Hook in and register a metabox for the admin comment edit page.
*/
function yourprefix_register_comment_metabox() {
/**
* Sample metabox to demonstrate each field type included
*/
$cmb = new_cmb2_box( array(
'id' => 'yourprefix_comment_metabox',
'title' => 'Test Metabox',
'object_types' => array( 'comment' ),
) );
$cmb->add_field( array(
'name' => 'Test Text Small',
'desc' => 'field description (optional)',
'id' => 'yourprefix_comment_textsmall',
'type' => 'text_small',
'column' => array(
'position' => 2,
'name' => 'CMB2 Custom Column',
),
) );
$cmb->add_field( array(
'name' => 'Test Color Picker',
'desc' => 'field description (optional)',
'id' => 'yourprefix_comment_colorpicker',
'type' => 'colorpicker',
'default' => '#ffffff',
'column' => array(
'position' => 2,
),
) );
}Documentation:
-
Installation
Installation instructions for various environments -
Basic Usage
Get up and running -
Advanced Usage
Not for the faint of heart -
Field Types
Breakdown of field types -
Examples
Examples for registering fields -
Field Parameters
Breakdown of common field parameters -
Display Options
Limit display of boxes -
Box Properties
Breakdown of box properties -
Troubleshooting
Common issues & how to deal with them -
Notable Changes in CMB2 (from original CMB)
CMB2 — a complete re-write -
Tips & Tricks
10x your CMB2 skills -
REST API
CMB2 data through WordPress REST API -
Javascript API
Work with CMB2 JS events & hooks
Advanced tutorials:
- Adding your own field types
- Adding your own show_on filters
- Displaying boxes on the front-end
- Using CMB to create an Admin Theme Options Page
- Create New Posts (or Custom Post Type) Entries Using A Front End Form
- Disable CMB2 Styles on Front End Forms
External Resources: