2

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;
}
add_filter('rewrite_rules_array','nng_users_rewrite_rules');

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

print_r( $wp_query->query_var );

or

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

  • 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
-2

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

http://codex.wordpress.org/Function_Reference/get_query_var

| improve this answer | |
  • Kind of a pointless answer, just pointing to the doc for the function. You should at least post the relevant part of the code that helped you. – The Unknown Dev Oct 20 '16 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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