I have added to my child theme functions.php:

function mychildtheme_register_query_vars( $vars ) {
    $vars[] = 'papers';
    return $vars;
}
add_filter( 'query_vars', 'mychildtheme_register_query_vars' );

When I try to query the var in another page

echo (get_query_var( $papers, $default='test' ));

the result is an empty string ('test' gets echoed), even if:

 global $wp_query;
 var_dump($wp_query->query_vars);

shows the vars and their values.

Any hints ? thanks

  • Please show the code where you "query the var in another page". And explaining what you're trying to achieve will also help alot understanding your problem – kero Dec 6 at 14:50
  • 2
    Very silly mistake on my part, sorry: I was trying to access a non-existing papers variable instead of 'papers' query var – Det Dec 7 at 0:11

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.