Notice: These forums are now retired and closed. For active support, please Submit a Ticket or visit our official WordPress.org community pages.
Kadence Theme | Kadence Blocks | Starter Templates | WooCommerce Email Designer | Ascend | Virtue | Pinnacle

cmb2_get_metabox ID Array?

Home / Forums / Virtue Theme / cmb2_get_metabox ID Array?

This topic is: Resolved
[Resolved]
Posted in: Virtue Theme
November 25, 2020 at 7:28 am

Hello Team Kadence!

Happy Thanksgiving!

I’m hoping you can help me with something. I need to target several metaboxes (updating the description field/options for sidebars). I’m using this as my function in my child theme:

function change_sidebar_metabox() {
$cmb = cmb2_get_metabox('bloggrid_metabox');
if (is_object($cmb)) {
$cmb->update_field_property('_kad_page_sidebar', 'name', __('Show/Hide Sidebar', 'virtue'));
$cmb->update_field_property('_kad_page_sidebar', 'desc', __('Without the sidebar, the layout will be fullwidth.', 'virtue'));
$cmb->update_field_property('_kad_page_sidebar', 'options', array(
'yes' => __('Show Sidebar', 'virtue'),
'no' => __('Hide Sidebar', 'virtue'),
));

$cmb->update_field_property('_kad_sidebar_choice', 'desc', __('If you have elected to hide the sidebar, choosing a sidebar will not change anything.', 'virtue'));
}
}

add_action('cmb2_init_before_hookup', 'change_sidebar_metabox', 21);

function change_sidebar_metabox2() {
$cmb = cmb2_get_metabox('blogliist_metabox');
if (is_object($cmb)) {
$cmb->update_field_property('_kad_page_sidebar', 'name', __('Show/Hide Sidebar', 'virtue'));
$cmb->update_field_property('_kad_page_sidebar', 'desc', __('Without the sidebar, the layout will be fullwidth.', 'virtue'));
$cmb->update_field_property('_kad_page_sidebar', 'options', array(
'yes' => __('Show Sidebar', 'virtue'),
'no' => __('Hide Sidebar', 'virtue'),
));

$cmb->update_field_property('_kad_sidebar_choice', 'desc', __('If you have elected to hide the sidebar, choosing a sidebar will not change anything.', 'virtue'));
}
}

add_action('cmb2_init_before_hookup', 'change_sidebar_metabox2', 21);

It works well but so far, I need to add it for each and every template I want to target (in this case both bloggrid_metabox and bloglist_metabox). From the CMB2 docs, cmb2_get_metabox should accept an array (unless I’m misunderstanding it). But no matter what I do, I just get a config error (id required) so I figure I’m doing it wrong or misunderstanding how to set this up. Setting them up separately causes the IDE to freak out about duplicate code so trying to combine the functions (and streamline the code and maintenance of said code). Is this something you can help me with? Thank you!

  • The forum ‘Virtue Theme’ is closed to new topics and replies.