Reputation: 4415
We have written a completely custom search for WordPress as we had very extensive needs for this.
The way it works is that when someone search, we execute our own query (custom mysql statement, including several UNION
s). This all works fine, however, for particular queries, we can't reach /page/2?s=***
. This page doesn't even end up on the search page, but goes to 404.
My assumption is that WordPress is first doing a search themselves and then also calculation how many results are to be shown, but because some search don't have any or enough results, the second page is not available.
It seems to me that the solution would be to replace the default WordPress search itself be our code, but I can't find anything online about actually replacing the search by your own query. Is this possible?
Alternatively, are there any ways how we can allow the /page/2/?s=
to go to the search page, where our code will handle the rest? Instead of getting a 404.
Upvotes: 0
Views: 817
Reputation: 591
Depending on how you are generating paginated links to more search results, I would recommend using a $_GET parameter to determine the current page, defaulting to page 1.
If you are using your own page template to render the search results, this is probably the most straightforward way to work around WordPress's default pagination functions:
/?s=search_here&s_page=1
For example. I have done this with custom plugins that have search and paginated results handled in a single page template.
Upvotes: 1