Created
June 14, 2012 21:40
-
-
Save jb510/2933115 to your computer and use it in GitHub Desktop.
CMB Class Show On filter for parent and ancestors only
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 | |
/** | |
* 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