WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#17016 closed enhancement (wontfix)

Empty search not allowed - makes it hard to build an enhanced search page

Reported by: jobjorn Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Template Keywords:
Focuses: Cc:

Description

Hello all,

I am building an enhanced search form for a recipe database (using a Star Trek LCARS-like interface!). The enhancement is primarily being able to select tags that the returned results should be tagged with. This is made possible in part through using query_posts(); in the landing page, search.php.

However, what if you want to search for *just* tags, and no text? You want to look at what's tagged both "cheese" and "tomato", and see no need to enter any search term. The result is that $_GET['s'] will be empty, and you will not get to search.php at all - and then you can't see your cheese+tomato recipes.

This is because wp-includes/query.php uses !empty rather than isset when trying to figure out whether we want to see a search page attached or not.

Extremely simple diff attached. If this solution is for some reason unacceptable, I would very much appreciate any ideas on how to work around the issue.

Attachments (2)

query.diff (415 bytes) - added by jobjorn 3 years ago.
Diff of wp-includes/query.php
query.2.diff (417 bytes) - added by jobjorn 3 years ago.
New, working, diff

Download all attachments as: .zip

Change History (7)

jobjorn3 years ago

Diff of wp-includes/query.php

comment:1 jobjorn3 years ago

This is related to #11330.

comment:2 jobjorn3 years ago

  • Keywords has-patch removed

Scratch that solution - it always returns true.

jobjorn3 years ago

New, working, diff

comment:3 jobjorn3 years ago

The just added attachment works as expected, but I suppose there is a good reason to use $qv['s'] rather than $_GET['s']?

comment:4 scribu3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

This would introduce a glaring inconsistency: all other empty query vars are ignored, while 's' gets special treatment. That's not a good idea, from an API point of view.

Also, by your definition of search, when you're going to /category/foo/ you're also doing a search, which is plainly wrong, in the WP universe.

For these reasons, I'm closing this ticket as wontfix.

Feel free to leave follow-up comments (without opening the ticket).

comment:5 scribu3 years ago

A workaround for your problem would be to modify the resulting posts (or rather the resulting query) before the actual template is loaded.

This can be done using one of 'parse_query' or 'pre_get_posts' actions. Plenty of tutorials for that on the web.

Version 1, edited 3 years ago by scribu (previous) (next) (diff)
Note: See TracTickets for help on using tickets.