get_query_var()
only works with the Core WP_Query
object:
Retrieve public query variable in the
WP_Query
class of theglobal
object.
$wp_queryhttps://codex.wordpress.org/Function_Reference/get_query_var
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.