admin管理员组

文章数量:1317898

I want to use blah/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?

I want to use blah/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?

Share Improve this question asked Oct 27, 2020 at 0:36 Doug CassidyDoug Cassidy 5787 silver badges17 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 2

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/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?

本文标签: