WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 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:

Description

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 4 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 @dd324 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.

comment:2 @baderatw4 years ago

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

@SergeyBiryukov4 years ago

comment:3 @SergeyBiryukov4 years ago

  • Keywords has-patch added

comment:4 @baderatw4 years ago

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

Thank you for the quick response!

comment:5 @dd324 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

comment:6 @baderatw4 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.

comment:7 @SergeyBiryukov4 years ago

  • Keywords has-patch removed

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

comment:8 @baderatw4 years ago

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

comment:9 @baderatw4 years ago

Got it. Your patch along with this:

query.php line 1387

/*, 's'*/

comment:10 @SergeyBiryukov4 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');

comment:11 @baderatw4 years ago

Ok - I un-commented 1387 and changed 1470 to

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

This works too.

comment:13 @SergeyBiryukov4 years ago

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