Skip to content

Instantly share code, notes, and snippets.

@jb510
Created June 14, 2012 21:40
Show Gist options
  • Save jb510/2933115 to your computer and use it in GitHub Desktop.
Save jb510/2933115 to your computer and use it in GitHub Desktop.
CMB Class Show On filter for parent and ancestors only
<?php
/**
* Include metabox only on children of Parent
* @author Jon Brown
* @link
*
* @param bool $display
* @param array $meta_box
* @return bool display metabox
*/
add_filter( 'cmb_show_on', 'sp_metabox_children_of_parent', 10, 2 );
function sp_metabox_children_of_parent( $display, $meta_box ) {
$cop_parent = array ('133'); // page ID of parent
if ( is_page($cop_parent) )
return $display; // we're at the parent page display metabox
$anc = get_post_ancestors( $post->ID );
foreach ( $anc as $ancestor ) {
if( is_page() && $ancestor == $pid ) {
return $display;
}
}
return false; // we arn't at the page or it's ancestors
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment