Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function site_child($pid) {
$site_term = io_multi_get_var('term', null); //this is working properly from another function
$args = array(
'child_of' => $pid,
'hierarchical' => 0,
'parent' => $pid,
);
// http://codex.wordpress.org/Function_Reference/get_pages
$children = get_pages($args);
foreach ($children as $child) {
if ( has_term($site_term,'site_assign',$child) ) {
return $child->ID;
}
}
return false;
}
// modify the PAGE main query
add_action( 'pre_get_posts', 'replace_content_with_child' );
function replace_content_with_child( $query ) {
if( $query->is_main_query() && !is_admin() && is_page() ) {
if( $sitechild = site_child($query->query_vars['page_id']) ) {
$query->query_vars['page_id'] = $sitechild;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment