CMB2 – how to add metabox inside an existing options page ?
-
CMB2 – how to add metabox to an existing options page (options page created also by new_cmb2_box)?
What do I want to accomplish ?`
1. Add new options-page with the use of new_cmb2_box -> this works OK.
add_action( 'cmb2_admin_init', 'register_metabox' ); function register_metabox() { $cmb = new_cmb2_box( array( 'id' => 'testtesttest', 'title' => '_Ustawienia_Motywu_', 'object_types' => array( 'options-page' ), 'option_key' => 'ustawienia_motywu', 'parent_slug' => 'options-general.php' ) ); }
2. To just created options page (point 1 above) add one meta box, again, with the use of new_cmb2_box -> THIS PART DOES NOT WORK – how to make it work ? :
add_action( 'cmb2_admin_init', 'register_metabox2' ); function register_metabox2() { $cmb2 = new_cmb2_box( array( 'id' => 'test2', 'title' => 'title', 'object_types' => array( 'options-page' ), 'parent_slug' => 'options-general.php?page=ustawienia_motywu', ) ); // Set our CMB2 fields $cmb2->add_field( array( 'name' => __( 'Test Text', 'myprefix' ), 'desc' => __( 'field description (optional)', 'myprefix' ), 'id' => 'test_text', 'type' => 'text', // 'default' => 'Default Text', ) ); $cmb2->add_field( array( 'name' => __( 'Test Color Picker', 'myprefix' ), 'desc' => __( 'field description (optional)', 'myprefix' ), 'id' => 'test_colorpicker', 'type' => 'colorpicker', 'default' => '#bada55', ) ); }
How to make #2 work ?
My guess is maby to use custom ‘show_on_cb’ …`- This topic was modified 3 years, 5 months ago by .
- This topic was modified 3 years, 5 months ago by .
- This topic was modified 3 years, 5 months ago by .
- This topic was modified 3 years, 5 months ago by .
- This topic was modified 3 years, 5 months ago by .
- This topic was modified 3 years, 5 months ago by .
- This topic was modified 3 years, 5 months ago by .
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘CMB2 – how to add metabox inside an existing options page ?’ is closed to new replies.