jon-b
6/14/2012 - 9:40 PM

CMB Class Show On filter for parent and ancestors only

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
}