Originally created for Post Status (https://poststatus.com/) to associate footnotes with notes, This CMB2 addon allows you to use CMB2 group fields to manage custom post type entries.
Originally created for Post Status to associate footnotes with notes, This CMB2 addon allows you to use CMB2 group fields to manage custom post type entries.
You will either need to clone and then run composer install
in this plugin’s directory to get the required dependencies, or simply download the compiled zip.
A few details:
'post_type_map'
parameter to your group field parameters.'id'
parameter to the same value as the wp_posts
database column name. So for the content, the 'id'
parameter would be 'post_content'
, or for the title, 'post_title'
.taxonomy_*
field types.You need to include this library:
require_once( 'cmb2-group-map/cmb2-group-map.php' );
Then setup a CMB2 metabox with a grouped field:
// Standard CMB2 registration.
$cmb = new_cmb2_box( array(
'id' => 'footnotes',
'title' => 'Footnotes',
'object_types' => array( 'post' ),
) );
// This is our group field registration. It's mostly standard.
$group_field_id = $cmb->add_field( array(
'id' => 'footnotes_ids',
'type' => 'group',
// This is a custom property, and should specify
// the destination post-type.
'post_type_map' => 'footnotes',
'description' => 'Manage/add connected footnotes',
'options' => array(
'group_title' => 'Footnote {#}',
'add_button' => 'Add New Footnote',
'remove_button' => 'Remove Footnote',
'sortable' => true,
),
) );
// by using 'post_title' as the id, this will be the
// value stored to the destination post-type's title field.
$cmb->add_group_field( $group_field_id, array(
'name' => 'Title',
'id' => 'post_title',
'type' => 'text',
) );
// by using 'post_content' as the id, this will be the
// value stored to the destination post-type's content field.
$cmb->add_group_field( $group_field_id, array(
'name' => 'Content',
'id' => 'post_content',
'type' => 'textarea_small',
) );
// This field will be stored as post-meta against
// the destination post-type.
$cmb->add_group_field( $group_field_id, array(
'name' => 'Color meta value',
'id' => 'footnote_color',
'type' => 'colorpicker',
) );
// This field will be stored as category terms
// against the destination post-type.
$cmb->add_group_field( $group_field_id, array(
'name' => 'Categories',
'id' => 'category',
'taxonomy' => 'category',
'type' => 'taxonomy_multicheck',
) );
Group Field Display
Group pulled from custom-post-type post
Post-select search modal