Unexpected Behavior in WordPress’ Custom Post Type Search Template

While creating the archive template for our Custom Post Types I ran into an unexpected behavior in the built in WordPress search or possibly a small bug.

First understand that we are only hooking into WordPress’ search template, we are not using any of the built in searching features of WordPress for various reasons. Second, Events and Tracks are both Custom Post Types, that being said lets look at the urls:


The urls load our default archive-{post_type}.php template. Note the search box above, if we inspect it’s html, we see that there is a hidden form field called “post_type”. This hidden form field is passed via $_GET and used in search.js to derive the search feed, either events.json or tracks.json (a cleaner way is in the works).

Bug(?) url: http://bmxraceevents.com/?s=maryland&post_type=events
Fixed url: http://bmxraceevents.com/?s=maryland&type=events

The bug url is loading the archive-{post_type}.php template, and not the search.php template. This appears to be happening because the variable post_type is reserved, the fix was simple, just change the variable name.



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>