Excluding posts or CPT by parent ID(s)
1
add_filter( 'asp_query_args', 'asp_exclude_by_parent_ids', 10, 2 );
2
function asp_exclude_by_parent_ids( $args, $id ) {
3
/**
4
* Enter the post/cpt parent IDs here, that you want to exclude
5
*/
6
$ids = array(1, 2, 3, 4, 5, 6);
7
8
// -- !! Do not change anything below this line !! --
9
$args['post_parent_exclude'] = $ids;
10
11
return $args;
12
}
Copied!
..same code, but to apply only for specific search instances:
1
add_filter( 'asp_query_args', 'asp_exclude_by_parent_ids', 10, 2 );
2
3
function asp_exclude_by_parent_ids( $args, $id ) {
4
/**
5
* Enter the post/cpt parent IDs here, that you want to exclude
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
// -- !! Do not change anything below this line !! --
15
// --------------------------------------------------
16
if ( in_array($id, $search_ids) )
17
$args['post_parent_exclude'] = $ids;
18
19
return $args;
20
}
Copied!
Last modified 1yr ago
Copy link