如何传递PHP$_GET变量并获取/输出它?

时间:2015-07-29 作者:Menno van der Krift

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.

1 个回复
SO网友:s_ha_dum

get_query_var() 仅适用于核心WP_Query 对象:

在中检索公共查询变量WP_Query 的类别global $wp_query 对象

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

您的错误很简单:关键是foo, 不bar.

$foo = $_GET[\'foo\'];
echo $foo;
但请不要echo 用户向页面提供的数据没有sanitizing it.

结束