Created
April 12, 2017 16:41
-
-
Save timothyjensen/ae66306c64b549f8dcf41d5ae00444a7 to your computer and use it in GitHub Desktop.
CMB2 on Genesis Archive Settings.
This file contains 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
<?php | |
add_action( 'cmb2_admin_init', 'yourprefix_register_demo_metabox' ); | |
/** | |
* Creating a metabox for a Genesis CPT Archive Settings page, where the CPT is 'webinars'. | |
*/ | |
function yourprefix_register_demo_metabox() { | |
/** | |
* Sample metabox to demonstrate each field type included | |
*/ | |
$cmb_demo = new_cmb2_box( array( | |
'id' => 'genesis-cpt-archive-settings-webinars-metabox', | |
'name' => __( 'Test Text', 'cmb2' ), | |
'hookup' => false, | |
'cmb_styles' => true, | |
'show_on' => array( | |
'key' => 'options-page', | |
'value' => 'genesis-cpt-archive-webinars', | |
), | |
) ); | |
$cmb_demo->add_field( array( | |
'name' => __( 'Test Text', 'cmb2' ), | |
'desc' => __( 'field description (optional)', 'cmb2' ), | |
'id' => 'genesis-cpt-archive-settings-webinars[test_text]', | |
'type' => 'text', | |
) ); | |
} | |
/** | |
* Hook in to the Genesis CPT Archive Settings form for 'webinars'. | |
*/ | |
add_action( 'webinars_page_genesis-cpt-archive-webinars_settings_page_boxes', function() { | |
$cmb = cmb2_get_metabox( 'genesis-cpt-archive-settings-webinars-metabox', 0, 'options-page' ); | |
$cmb->show_form(); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Justin, the last thing to iron out is populating the field after the data is saved to the options table. I can retrieve the option using
But the value is not populated in the CMB2 field; it remains empty after the page refreshes. See https://cl.ly/1J202h101f3x