Why does the $_GET parameter ?search forward the front-page to the archive/blog page

I need the $_GET parameter ?search for my front-page for a third party plugin.
Whenever I enter http://wp-site.tld/?search=foo I get redirected to the blog/archive page.
If I enter http://wp-site.tld/some-page/?search I get redirected to /some-page.
It appears to be a redirection only for the front-page.

Am I missing something from the docs?

Steps to reproduce:

  1. Go to a WP website and add ?search to your front-page URL
  2. Go to a WP website and add ?search to a random sub-page URL

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

search is a reserved term, and should not be used as a query variable. The presence of any reserved query variable tells WordPress that the current query must be for something other than the front page, so it interprets it as an an archive query of some sort.

The reason you get redirected to the canonical URL on other pages is because being on another page means that there are some other query variables being set that tell WordPress which page to load. These aren’t present on the homepage, hence the fallback to just the blog.

The parameter doesn’t actually do anything though, and hasn’t for at least 15 years, but it’s still reserved for possible future use.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x