Using pre_get_posts to filter out posts, pagination problem
You should probably return the user to the first page of results following a search in all scenarios, to be consistent. If you did need to check though you can use the following: $wp_query->max_num_pages; So if there’s only 2 pages and you’re on page 3 then you need to redirect to the start.