function site_child($pid) { | |
$site_term = io_multi_get_var('term', null); //this is coming from a different function. it works. | |
$args = array( | |
'child_of' => $pid, | |
'hierarchical' => 0, | |
); | |
// http://codex.wordpress.org/Function_Reference/get_pages | |
$children = get_pages($args); | |
foreach ($children as $child) { | |
if ( has_term($site_term,'site_assign',$child) ) { | |
//echo $child->ID; | |
return $child->ID; | |
} | |
} | |
return false; | |
} | |
// modify the PAGE main query | |
function replace_content_with_child( $query ) { | |
global $wp_query; | |
if( $query->is_main_query() && !is_admin() && is_page() ) { | |
$id = get_queried_object_id(); | |
if( $sitechild = site_child($id) ) { | |
$query->query_vars['page_id'] = $sitechild; | |
} | |
} | |
} | |
add_action( 'pre_get_posts', 'replace_content_with_child' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment