This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: 'post_parent' != 1

#24516
am12313am12313
Participant

Hey, Thanks.

I need to be able to do this programmatically. Can I use the above code?

The reason is: I need to exclude all posts where post_parent == 0. In other words, I want only child posts to appear in the search.

My solution was this:

$args1 = [
‘post_type’ => ‘wines’,
‘post_parent’ => 0,
‘nopaging’ => true,
‘fields’ => ‘ids’
];
$ids = get_posts( $args1 );
add_filter( ‘asp_query_args’, ‘asp_exclude_by_ids’, 10, 2 );

function asp_exclude_by_ids( $args, $id ) {

$args[‘post__not_in’] = $ids;
return $args;
}

However, that code does not appear to be compatible.

Thank you.