I've already looked at the Wordpress Codex, and looked around for other solutions online, but i still can't seem to get it working. Basicly what i need is to pass a GET variable in an URL, and output it on the next page.

Link http://www.website.com?foo=bar

I've aleady tried fetching the GET variable like below:
$foo = get_query_var( 'foo' ); echo $foo;
And doesn't seem to work.

Also tried the more PHP oriented way:
$foo = $_GET['foo'];
Also, without success.

Any help on the matter would be most appreciated.

  • It's strange that $_GET['foo'] doesn't work. What about standard WordPress query variables, does ?s=foo in the URL result in a search? Can you output $_GET['s'] in the code?
    – kovshenin
    Jul 29, 2015 at 19:08
  • Yes, ?s=foo redirects to the search(results) page. Jul 30, 2015 at 10:21

1 Answer 1


get_query_var() only works with the Core WP_Query object:

Retrieve public query variable in the WP_Query class of the global $wp_query object.


Your mistake is a simple PHP one: The key is foo, not bar.

$foo = $_GET['foo'];
echo $foo;

But please do not echo user supplied data to the page without sanitizing it.

  • Whoops, edited the question. In my actual code i had the key right though. But still, nothing. On the codex page it says<br> $page = get_query_var( 'page', 1 ); With 'page' being the key, and the '1' being the default value? I've just tried this and also doesn't work for me. Then again, isn't that what i've already tried before? (See question). Jul 29, 2015 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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