show_on – exclude on template
-
I’m trying to modify this filter:
https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Adding-your-own-show_on-filters#example-page-template-show_on-filterit doesn’t seem to prevent the box from showing:
functions.php
function be_metabox_exclude_on_template( $display, $meta_box ) {if( 'exclude_template' !== $meta_box['show_on']['key'] )
return $display;// Get the current ID
if( isset( $_GET['post'] ) ) $post_id = $_GET['post'];
elseif( isset( $_POST['post_ID'] ) ) $post_id = $_POST['post_ID'];
if( !isset( $post_id ) ) return false;$template_name = get_page_template_slug( $post_id );
$template_name = substr($template_name, 0, -4);// If value isn't an array, turn it into one
$meta_box['show_on']['value'] = !is_array( $meta_box['show_on']['value'] ) ? array( $meta_box['show_on']['value'] ) : $meta_box['show_on']['value'];// See if there's a match
if( in_array( $template_name, $meta_box['show_on']['value'] ) ) {
return false;
} else {
return true;
}
}
add_filter( 'cmb_show_on', 'be_metabox_exclude_on_template', 10, 2 );initiating the cmb2 metabox:
$cmb = new_cmb2_box( array(
'id' => 'perpage',
'title' => __( 'Per Page Specifics', 'rnr3' ),
'object_types' => array( 'page' ), // Post type
'context' => 'side',
'show_on' => array( 'key' => 'exclude_template', 'value' => 'bling.php' ),
'priority' => 'high',
'show_names' => true // Show field names on the left
) );i don’t want it to show up a page that uses the “bling.php” template. what am i doing wrong?
The topic ‘show_on – exclude on template’ is closed to new replies.