Make WordPress Core

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#21009 closed defect (bug) (invalid)

If name="post_type" is set in search template the archive template is loaded.

Reported by: ZaneMatthew Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.4
Component: Posts, Post Types Keywords: reporter-feedback close
Focuses: Cc:


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:


Fixed url:



Change History (14)

#1 @SergeyBiryukov
9 years ago

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

#2 @ZaneMatthew
9 years ago

I did, my fix is in the description. Just wanted to bring this to someones attention.

#3 @nacin
9 years ago

s= should always force a search template. Looks like a legitimate bug.

#4 @SergeyBiryukov
9 years ago

Ah, I see. Can't reproduce though.

  1. Created "book" post type using the basic example from Codex.
  2. Added a new book, "Around the World in Eighty Days".
  3. Tested /?s=around&type=book and /?s=around&post_type=book URLs with Twenty Eleven.
  4. Both resulting pages use the search template.
Last edited 9 years ago by SergeyBiryukov (previous) (diff)

#5 @ericlewis
9 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.

#6 @ZaneMatthew
9 years ago

Thanks for looking into it, guess its something buggy on my end.

#7 @nacin
9 years ago

  • Keywords reporter-feedback added

#8 @WraithKenny
9 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 @WraithKenny
9 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.

#10 @WraithKenny
9 years ago

again nevermind, 2011 also has an archive.php. I don't know why it's happening.

#11 @WraithKenny
9 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.

#12 @WraithKenny
9 years ago

found it. the most obvious cause: no search.php

#13 @webord
8 years ago

  • Keywords close added
  • Resolution set to invalid
  • Status changed from new to closed

If it's fixed then I'm closing the Ticket.

#14 @helen
8 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.