Skip Navigation

[Resolved] Adding theme metaboxes to the Toolset template (not individual custom posts)

This support ticket is created 3 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 3 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#2208933
Screen Shot 2021-10-11 at 3.55.26 PM.png

We have around 350 content items (custom posts). We're trying to add our theme's (The7) metaboxes to the pages and have been partially successful. We were able to add the metaboxes to the individual custom posts, but we want to apply the same styling to all 350+ pages so we're hoping there's a way to add the metaboxes to the Toolset template page itself (see screenshot) so we can adjust that styling for all pages of that custom post type. This is also important because an API will pull in new content items as they're created by the content provider, and we won't always know when they're added (and be able to individually style them if we stick with the method we've had success with).

- - -

After much research, here is how i finally got the metaboxes enabled on the CPT.

add_action( 'init', 'dt_add_product_metaboxes_custom', 30 );
function dt_add_product_metaboxes_custom() {

global $DT_META_BOXES;

if ( $DT_META_BOXES && is_admin()) {

foreach ( array( 'dt_page_box-sidebar', 'dt_page_box-footer', 'dt_page_box-header_options', 'dt_page_box-slideshow_options', 'dt_page_box-fancy_header_options' ) as $mb_id ) {
if ( isset($DT_META_BOXES[ $mb_id ], $DT_META_BOXES[ $mb_id ]['pages']) ) {
$DT_META_BOXES[ $mb_id ]['pages'] = array('vetprepce_vetstream', 'post', 'page');
}
}
}
}

add_filter( 'presscore_pages_with_basic_meta_boxes', 'vs_presscore_pages_with_basic_meta_boxes' );
function vs_presscore_pages_with_basic_meta_boxes( $post_type_array ) {
$post_type_array = array( 'page', 'post', 'vetprepce_vetstream' );
return $post_type_array;
}

This however only adds to the individual CPT posts, and not the toolset template.

I also tried was suggested in this article and several similar articles https://toolset.com/documentation/programmer-reference/theme-support-for-content-templates/ with no success. And, a lot of time looking through the Toolset plugin source code to see if there was a hook, filter or action I could use but no dice 🙁

#2209803

Hello,

Toolset content template is a custom post type, the post type slug is "view-template", you can follow WP document to add metabox into it:
https://developer.wordpress.org/reference/functions/add_meta_box/

for example:

/**
 * Register meta box(es).
 */
function wpdocs_register_meta_boxes() {
    add_meta_box( 'meta-box-id', __( 'My Meta Box', 'textdomain' ), 'wpdocs_my_display_callback', 'view-template' );
}
add_action( 'add_meta_boxes', 'wpdocs_register_meta_boxes' );
 
/**
 * Meta box display callback.
 *
 * @param WP_Post $post Current post object.
 */
function wpdocs_my_display_callback( $post ) {
    // Display code/markup goes here. Don't forget to include nonces!
	echo 'Display code/markup goes here. Dont forget to include nonces!';
}
 
/**
 * Save meta box content.
 *
 * @param int $post_id Post ID
 */
function wpdocs_save_meta_box( $post_id ) {
    // Save logic goes here. Don't forget to include nonce checks!
}
add_action( 'save_post', 'wpdocs_save_meta_box' );