With the following code I can exclude all posts and pages that are top-level, but I would like to apply this only to pages, not to posts (but I still want all posts in the results):
function search_filter( $query )
{
if(
$query->is_search
AND $query->is_main_query()
)
{
$query->set( 'post_parent__not_in', array( 0 ) );
$query->set( 'post_type', array( 'post', 'page' ) );
}
return $query;
}
At the moment all my posts have 0 as post_parent, so they all get excluded from the results.
I wonder if this will work for you:
and