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
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
scroll top