Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#27209 closed feature request (duplicate)

Add a has_query_var function

Reported by: ndobie's profile ndobie Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8.1
Component: Query Keywords:
Focuses: Cc:


Because get_query_var returns an empty string even if the query var is not set, you have to use the global $wp_query variable to check if it is set when using a custom endpoint that does not need a value.

For example I have a plugin that returns statistics on tags and categories by adding a /stats/ endpoint. I currently have to evaluate as so:

global $wp_query;

// Skip if not a stats request
if (!(isset($wp_query->query_vars['stats']) && (is_tag() || is_category()))) {

I'd like to just be able to use the following:

// Skip if not a stats request
if (!(has_query_var('stats') && (is_tag() || is_category()))) {

Alternatively get_query_var could return a NULL value when the query var doesn't exist.

Change History (1)

#1 @helen
10 years ago

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

Closing as a duplicate of #16471, which took the place of #15178 and #19243.

Note: See TracTickets for help on using tickets.