#21009 closed defect (bug) (invalid)
If name="post_type" is set in search template the archive template is loaded.
| Reported by: | ZaneMatthew | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Posts, Post Types | Version: | 3.4 |
| Severity: | minor | Keywords: | reporter-feedback close |
| Cc: | Focuses: |
Description
I have a hidden form field named "post_type", which is used in the search form. When the user searches the archive.php template is loaded and not the search.php template.
I'm not sure if this is a bug, or unexpected behavior, note my fix was to use a different form field name.
Bug(?) url:
http://bmxraceevents.com/?s=maryland&post_type=events
Fixed url:
http://bmxraceevents.com/?s=maryland&type=events
http://zanematthew.com/blog/2012/06/unexpected-behavior-in-wordpress-custom-post-type-search-template/
Change History (14)
#2
@
14 years ago
I did, my fix is in the description. Just wanted to bring this to someones attention.
#4
@
14 years ago
Ah, I see. Can't reproduce though.
- Created "book" post type using the basic example from Codex.
- Added a new book, "Around the World in Eighty Days".
- Tested /?s=around&type=book and /?s=around&post_type=book URLs with Twenty Eleven.
- Both resulting pages use the search template.
#5
@
14 years ago
I can't reproduce either following @SergeyBiryukov's steps and also creating a custom archive template for the 'book' CPT, which loaded the search template.
#8
@
14 years ago
I've duplicated this. I think is has to do with a conflict here:
...
'rewrite' => array('slug' => 'recipes'),
'query_var' => true,
'has_archive' => true,
...
where the archive rewrite trumps the search.
www.example.com/?post_type=recipes goes to the archive like it's supposed to, and www.example.com/?s=meat goes to search, but www.example.com/?s=meat&post_type=recipes loads up the archive.
It's probably the 'query_var' doing it right? I agree with Nacin about s trumping the 'query_var'.
#9
@
14 years ago
Nevermind, changing that had no effect and the example code on the codex included it. I was able to *reliably* replicate by adding and deleting the archive-recipes.php file tho; My theme doesn't have a generic archive.php file.
#11
@
14 years ago
anyway, the least I can offer is a symptom: that www.example.com/?s=meat&post_type=recipes gives me (via debug-bar)
Query Type: Search Query Template: archive-recipes.php
and wp_title() gives me the Search page's title, while loading up the wrong template.
I'll keep looking to see if I can find the cause.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
If that's a custom search form, why don't you rename the hidden field to
type?