Post Data to WordPress Permalink 404 Not Found

Do you know that when you post data to a WordPress permalink, data field name might conflict with reserved query variables in WordPress, and end up a 404 not found response?

In my case I have a ‘name’ field that I want to post back to a permalink in my WordPress application, while I am absolutely sure the permalink is right, but I always get 404 response from WordPress. Through a few lines debugging I found the answer to this strange behaviour.

This is only applying to submit data back to a permalink, not a problem if data is submitted back to a file, as request of a file is not handled by WordPress.
When request is a permalink, the requested url will be parsed by WordPress, during the process, WordPress has a list of reserved query variable s to check against your request. If matches are found, then the values will be treated as variable values to query your blog post or page rather than user data, which very likely will end up not found error.

There are two reserved variable lists, public_query_vars and private_query_vars


var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 
'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged',
'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute',
'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename',
'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost',
'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type');

var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page',
'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in',
'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and',
'tag_id', 'post_mime_type', 'perm', 'comments_per_page');

All the words within these two lists are reserved, therefore should not be used as field name for user data. So you can see why I can not post a ‘name’ field as ‘name’ is a public query var.

Tags:

This entry was posted on Thursday, March 24th, 2011 at 3:15 am and is filed under PHP. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

5 Responses to “Post Data to WordPress Permalink 404 Not Found”

  1. In Pokemon, is Dialga stronger or Palkia. I’m asking this cos Palkia looks better but Dialga is like gangster as!
    Cheers mate!!!
    I’m like gangster as!!!!

  2. Dan says:

    i had the same problem – trying to integrate worldpay – i pointed the callback to a wordpress permalink and it took ages to find out what the problem was – apparently worldpay sends a “name” field within the callback post data… -.-…

  3. rosh says:

    The permalink issue is only because of the ‘%’ if you can change the char it will work, or you can update the database for changing the permalink option.

Leave a Reply

*