WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wish to create a new variable as described in the codex, but on submission of the URL the variables are submitted twice to my function

I have tried this within a plugin also a the function.php. I have also tried to use wp_reset_query()

Here is my sample code:

add_filter('query_vars', 'my_function');
function my_function ($vars) {    
  $vars[] = 'Q1';
  $vars[] = 'Q2';    
  return $vars;    

add_action('parse_query', 'query_var');    
function query_var () {    
  if (get_query_var('Q1')){    
    echo ('hello');    
share|improve this question
up vote 0 down vote accepted

The parse_query action gets called on every query (menu items, sidebar recent posts widgets, etc.), but get_query_var pulls from the main query, so that condition will be true for all queries despite the fact that the query var doesn't exist in those queries. You need to check the query object passed to your function hooked to parse_query:

add_action('parse_query', 'query_var'); 
function query_var( $query ) { 
  if ( isset( $query->query_vars['Q1'] ) ){    
    echo ('hello');    
share|improve this answer
AH HA Thanks , I knew i missed some thing !! – user34416 Jun 22 '13 at 16:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.