pre_get_post filter returns results when there should not be

Assuming that you get an empty array for $post_ids if there are no matching posts, I think this is wrong:

if ( $post_ids ) {}

Because the array exists, but is empty. Try to check for an empty array:

if ( ! empty( $post_ids ) ) {}

Leave a Comment