Opened 11 months ago
Last modified 8 months ago
#21009 new defect (bug)
If name="post_type" is set in search template the archive template is loaded.
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Post Types | Version: | 3.4 |
| Severity: | minor | Keywords: | reporter-feedback |
| Cc: |
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 (12)
comment:1
SergeyBiryukov — 11 months ago
comment:2
ZaneMatthew — 11 months ago
I did, my fix is in the description. Just wanted to bring this to someones attention.
s= should always force a search template. Looks like a legitimate bug.
comment:4
SergeyBiryukov — 11 months 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.
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.
comment:6
ZaneMatthew — 11 months ago
Thanks for looking into it, guess its something buggy on my end.
comment:8
WraithKenny — 8 months 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'.
comment:9
WraithKenny — 8 months 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.
comment:10
WraithKenny — 8 months ago
again nevermind, 2011 also has an archive.php. I don't know why it's happening.
comment:11
WraithKenny — 8 months 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.
comment:12
WraithKenny — 8 months ago
found it. the most obvious cause: no search.php

If that's a custom search form, why don't you rename the hidden field to type?