-
Notifications
You must be signed in to change notification settings - Fork 566
Closed
Description
Versions
- CMB 2.4.2
- WP 4.9.8
Expected Behavior:
When registering metaboxes for two different custom post types to be visible in the REST API (using /wp/v2/{post_type}) the 'cmb2' object in REST response will only contain the metaboxes for that post type.
Actual Behavior:
The REST response for both post types contains all metaboxes, albeit the fields in the boxes not registered to that post type all have empty values
Steps to reproduce (I have confirmed I can reproduce this issue on the trunk branch):
- Register two custom post types, each with
show_in_rest => true - Create a CMB2 metabox for each post type, again with
show_in_rest => true - Ensure they are initialised on the
cmb2_inithook instead ofcmb2_admin_init - Inspect the REST API response for either post type - they should show object for both metaboxes under the
cmb2key, the correct one will be populated with values, the other will not
CMB2 Field Registration Code:
// Metabox for 'office' CPT
add_action( 'cmb2_init', 'office_register_metabox' );
function office_register_metabox() {
$cmb = new_cmb2_box( array(
'id' => 'office_description_metabox',
'title' => esc_html__( 'Office info', 'domain' ),
'object_types' => 'office',
'show_in_rest' => true,
) );
// Fields are irrelevant - they could be any fields
$cmb->add_field( array(
// Field Config...
) );
}
// Metabox for 'country' CPT
add_action( 'cmb2_init', 'country_register_metabox' );
function country_register_metabox() {
$cmb = new_cmb2_box( array(
'id' => 'country_description_metabox',
'title' => esc_html__( 'Country info', 'domain' ),
'object_types' => 'country',
'show_in_rest' => true,
) );
// Fields are irrelevant - they could be any fields
$cmb->add_field( array(
// Field Config...
) );
}Metadata
Metadata
Assignees
Labels
No labels
