using pre_get_posts for search results not found

Like others have said you can’t use pre get posts since there is no way of knowing if the search returned any posts. I would also say that the if else is a very clean way to do it and might be the better choice if anyone else is going to be working on this.

But if you really wanted to do it with a filter on either the posts_results or the_posts to return the replacement posts that should be shown if the search is empty.

<?php

add_filter('the_posts', 'np_replace_empty_search', 10, 2);
function np_replace_empty_search($posts, $wp_query){
    if($wp_query->is_search && empty($posts)){
        $new_query = new WP_Query();

        return $new_query->posts;
    }
    return $posts;
}