Make WordPress Core

Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#21009 closed defect (bug) (invalid)

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

Reported by: zanematthew's profile ZaneMatthew Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.4
Component: Posts, Post Types Keywords: reporter-feedback close
Focuses: 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 (14)

#1 @SergeyBiryukov
12 years ago

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

#2 @ZaneMatthew
12 years ago

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

#3 @nacin
12 years ago

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

#4 @SergeyBiryukov
12 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 12 years ago by SergeyBiryukov (previous) (diff)

#5 @ericlewis
12 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
12 years ago

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

#7 @nacin
12 years ago

  • Keywords reporter-feedback added

#8 @WraithKenny
12 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
12 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
12 years ago

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

#11 @WraithKenny
12 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
12 years ago

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

#13 @webord
11 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
11 years ago

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