Limit results to current page children
Results only where the current post (or page or any cpt) is the parent
1
add_filter('asp_query_args', 'asp_add_current_parent_dependency', 10, 1);
2
function asp_add_current_parent_dependency($args) {
3
if ( !empty($args['_page_id']) ) {
4
$args['post_parent'][] = $args['_page_id'];
5
$args['post_parent'] = array_unique($args['post_parent']);
6
}
7
8
return $args;
9
}
Copied!
..same code, but to apply only for specific search instances:
1
add_filter('asp_query_args', 'asp_add_current_parent_dependency', 10, 2);
2
function asp_add_current_parent_dependency( $args, $id ) {
3
/**
4
* Search instance IDs you want this code to apply on.
5
*/
6
$search_ids = array(1, 2);
7
8
// -- !! Do not change anything below this line !! --
9
// --------------------------------------------------
10
if ( !empty($args['_page_id']) && in_array($id, $search_ids) ) {
11
$args['post_parent'][] = $args['_page_id'];
12
$args['post_parent'] = array_unique($args['post_parent']);
13
}
14
15
return $args;
16
}
Copied!
Last modified 10mo ago
Copy link