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 have a problem writing a plugin for wordpress. First, I register a new query_var and add a new rewrite rule:

function nng_users_query_vars( $vars ) {
    array_push( $vars, 'nng_users' );
    return $vars;
add_filter('query_vars', 'nng_users_query_vars');

function nng_users_rewrite_rules( $rules ) {
$newrules = array(
                        'benutzer/([^/]+)/?$' => 'index.php?pagename=nng_users&nng_users=$matches[1]'
$finalrules = $newrules + $rules;
    return $finalrules;

This works perfectly, but I cannot grab any query_var from the plugin. Typing:

print_r( $wp_query->query_var );


echo $wp_query->query_var['some_var'];

does not show anything. But why? If I put the exact same thing into the function of my theme, it works. If I put it into a function and call this function in my theme, it works... Background is the following: I want to create a custom user system and therefore I need to check my custom query var to e.g. logout or header-redirect.

Thanks in advance

share|improve this question
and of course I tried to global $wp_query – clash Jul 29 '12 at 11:54
is $wp_query->query_var a typo? it's plural: $wp_query->query_vars – Milo Jul 29 '12 at 13:47
its a typo, sry about that. I used $wp_query->query_vars of course – clash Jul 29 '12 at 15:21

Late answer, but for everybody else looking for it, this works:


share|improve this answer

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.