WordPress has a list of reserved words, can I override them, to use one in a query string?

I want to use blah.com/myscript/?year=2020
But this causes a 404 (and yet the page loads). However, it seems as though trying to serve a download is borked, because of the year parameter. Is there a way to disable wp’s grip on this simple word?

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

No.

You could try to remove year from the whitelist of query variables, but this would cripple date archives, break all date based filtering in WP Admin, as well as break any plugins or themes that rely on this functionality. This doesn’t just impact user interface, but any date based query internally

E.g. sitemaps in core would break, year based RSS and REST API requests, as would all the admin dropdown filters, calendar widgets, and any time based logic in recent posts queries, etc.

Suffice to say the damage could be significant

These are not just URL variables, query variables run much much deeper and are the keys to parameters in WP_Query, hence the name. They’re the key component that makes rewrite rules work. When you visit example.com/2019 it gets mapped on to index.php?year=2019 which becomes WP_Query( [ 'year' => 2019, ... ] ), etc As far as WordPress is concerned, /2019 /index.php?year=2019 and /?year=2019 are all exactly the same

As for removing that query var, it might be necessary to fork WordPress to do it. This is one of those situations where saving yourself 5 minutes could involve 5+ years of effort, it is not a profitable trade.

Have you considered renaming your variable instead? Perhaps archive_date or filter_date?


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