Opened 11 years ago
Closed 11 years ago
#27209 closed feature request (duplicate)
Add a has_query_var function
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.8.1 |
Component: | Query | Keywords: | |
Focuses: | Cc: |
Description
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()))) { return; }
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()))) { return; }
Alternatively get_query_var
could return a NULL
value when the query var doesn't exist.
Change History (1)
Note: See
TracTickets for help on using
tickets.
Closing as a duplicate of #16471, which took the place of #15178 and #19243.