WordPress Reserved Terms and Post Requests
Forms, PHP, WordPress
When submitting a form to a WordPress site, there are a number of reserved keywords that should not be used as name attributes - including “name”, “author” and “type”. Using such keywords may result in odd errors - either unexplained 404 errors or the template reverting to the index.php
template.
The latter error looks particularly odd, because the permalink is unchanged. Debugging $_POST
and $_REQUEST
names in this context is not simple.
Most recently, when refactoring a project I managed to completely break form submission. The natural assumption is that there is a problem with your code. Eight hours of git resets and diffs later, I realized that I had set a form field with the name attribute “name” - coincidence can be a bitch.
Since I’ve cumulatively wasted a couple of days of my life on this issue, I’m documenting it here to prevent future nervous meltdowns.
Prefix all Form Names
A good general rule for WordPress forms is:
PREFIX FORM NAMES
Reserved Keywords
I can personally attest that you need to avoid the string “name” as a name attribute (use “my_prefix_name” instead). The rest of the list is taken from the WordPress Codex:
- attachment
- attachment_id
- author
- author_name
- calendar
- cat
- category
- category__and
- category__in
- category__not_in
- category_name
- comments_per_page
- comments_popup
- custom
- customize_messenger_channel
- customized
- cpage
- day
- debug
- embed
- error
- exact
- feed
- hour
- link_category
- m
- minute
- monthnum
- more
- name
- nav_menu
- nonce
- nopaging
- offset
- order
- orderby
- p
- page
- page_id
- paged
- pagename
- pb
- perm
- post
- post__in
- post__not_in
- post_format
- post_mime_type
- post_status
- post_tag
- post_type
- posts
- posts_per_archive_page
- posts_per_page
- preview
- robots
- s
- search
- second
- sentence
- showposts
- static
- subpost
- subpost_id
- tag
- tag__and
- tag__in
- tag__not_in
- tag_id
- tag_slug__and
- tag_slug__in
- taxonomy
- tb
- term
- terms
- theme
- title
- type
- w
- withcomments
- withoutcomments
- year
There is a more extensive list here.
References
comments powered by Disqus