Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#18485 closed defect (bug) (duplicate)

Search with blank criteria returns results in wrong template file.

Reported by: baderatw Owned by:
Milestone: Priority: normal
Severity: major Version: 3.2.1
Component: Template Keywords:
Focuses: Cc:


If you use the search but leave the criteria field blank, the results are returned in the standard template instead of search.php

Attachments (1)

18485.patch (408 bytes) - added by SergeyBiryukov 10 years ago.

Download all attachments as: .zip

Change History (14)

#1 @dd32
10 years ago

Just to confirm, You're refering to something such as: http://example.com/?s= ?

WordPress treats empty query vars as if they don't exist, therefor, in that situation it'd most likely load the blog index.

#2 @baderatw
10 years ago

Yes, that's exactly what I mean. Rather inconvenient because it's probable that a user could click search with no criteria...

#3 @SergeyBiryukov
10 years ago

  • Keywords has-patch added

#4 @baderatw
10 years ago

  • Resolution set to fixed
  • Status changed from new to closed

Thank you for the quick response!

#5 @dd32
10 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Tickets are closed when a commit is made to the WordPress trunk to fix the issue, not when a patch is posted

#6 @baderatw
10 years ago

Yeah, that fix didn't work anyway. I thought it did... but when I looked back at the root of the site, every page is showing up as search results template now.

#7 @SergeyBiryukov
10 years ago

  • Keywords has-patch removed

Yep, scratch that. I should have tested more thoroughly.

#8 @baderatw
10 years ago

Is there somewhere else in the code that the $qvs? variable is checked in regards to templates?

#9 @baderatw
10 years ago

Got it. Your patch along with this:

query.php line 1387

/*, 's'*/

#10 @SergeyBiryukov
10 years ago

WordPress prefills all query vars (including s) with empty values, so that's probably by design.

A workaround might look like this:

function load_search_template_for_blank_criteria() {
	global $wp_query;
	if ( isset( $_GET['s'] ) )
		$wp_query->is_search = true;
add_action('template_redirect', 'load_search_template_for_blank_criteria');

#11 @baderatw
10 years ago

Ok - I un-commented 1387 and changed 1470 to

if (isset($_GET['s'])) {

This works too.

#13 @SergeyBiryukov
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.