Query String being Removed Creating a Pagination Issue within a Custom Plugin

I don’t believe this is an issue with a WP update, but rather an issue that has always been there but unnoticed:

$page = get_query_var('page');

page is a query var, yet it’s being reused. As a result, when you ask for page 2, you are not asking for page 2 of the custom results, that’s just a coincidence.

Instead you are asking for page 2 of the main query, the main post loop that loaded the page and template. But there is no page 2.

This regularly happens to people who don’t know how to modify the main query and create replacement post loops. Their custom post loops have a page 3, but the main query does not, so page 3 gives them a 404.

Since this is a custom SQL query, the fix is easy, don’t reuse reserved keywords such as page from the main query/URL for custom queries.