[wp-trac] [WordPress Trac] #27209: Add a has_query_var function

WordPress Trac noreply at wordpress.org
Tue Feb 25 17:12:20 UTC 2014


#27209: Add a has_query_var function
-----------------------------+-----------------------------
 Reporter:  ndobie           |      Owner:
     Type:  feature request  |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Query            |    Version:  3.8.1
 Severity:  normal           |   Keywords:
  Focuses:                   |
-----------------------------+-----------------------------
 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.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/27209>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list