Make WordPress Core

Opened 4 years ago

Closed 22 months ago

#19243 closed enhancement (duplicate)

Introduce WP_Query::exists(), or have WP_Query::get() return false for non-existence

Reported by: nacin Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Query Keywords: needs-patch
Focuses: Cc:


See 15178#comment:8.

A query variable for an an endpoint with no value (/blah/, rather than /feed/rss2/) is set, but it is empty. WP_Query::get() returns an empty string when no QV is set, though, so you need to dig into WP_Query::query_vars directly. This is annoying. It should return false when the QV is not existence.

This should be rather backwards compatible, but WP_Query::exists() may be desired (also, or instead of). In this case, it won't work for core query vars, as _fill_query_vars() clears these, rather than unsets them. We should either change how _fill_query_vars() works, or something.

Change History (5)

#1 @mintindeed
4 years ago

  • Cc gabriel.koen@… added

#2 @WraithKenny
4 years ago

http://core.trac.wordpress.org/ticket/16303#comment:1 Westi's code there suggests a workaround: you can hook to 'request' and set the var to true if isset but empty, then when checking get_query_var in template_redirect or wherever, if it's false or empty then it hadn't been set.

#3 @c3mdigital
2 years ago

  • Keywords needs-patch added

#5 @nacin
22 months ago

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

Duplicate of #16471.

Note: See TracTickets for help on using tickets.