How to pass a PHP $_GET variable and fetch/output it?

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.


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.

1 Answer

get_query_var() only works with the Core WP_Query object:

Retrieve public query variable in the WP_Query class of the global

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.

Leave a Comment