Limiting results to specific posts by parent ID
While there is no option to limit the results pool to posts with specific parents only, it is possible with a filter, very easily.
1
add_filter( 'asp_query_args', 'asp_include_only_parent_ids', 10, 2 );
2
function asp_include_only_parent_ids( $args, $id ) {
3
/**
4
* Enter the post/cpt prent IDs here. The results will be
5
* limited to objects with these parent IDs.
6
*/
7
$ids = array(1, 2, 3, 4, 5, 6);
8
9
// -- !! Do not change anything below this line !! --
10
$args['post_parent'] = $ids;
11
12
return $args;
13
}
Copied!
..same code, but to apply only for specific search instances:
1
add_filter( 'asp_query_args', 'asp_include_only_parent_ids', 10, 2 );
2
function asp_include_only_parent_ids( $args, $id ) {
3
/**
4
* Enter the post/cpt prent IDs here. The results will be
5
* limited to objects with these parent IDs.
6
*/
7
$ids = array(1, 2, 3, 4, 5, 6);
8
/**
9
* Search instance IDs you want this code to apply on.
10
*/
11
$search_ids = array(1, 2);
12
13
// --------------------------------------------------
14
// --------------------------------------------------
15
// -- !! Do not change anything below this line !! --
16
// --------------------------------------------------
17
if ( in_array($id, $search_ids) )
18
$args['post_parent'] = $ids;
19
20
return $args;
21
}
Copied!
Last modified 1yr ago
Copy link