简体   繁体   English

$ _GET始终返回null

[英]$_GET always returning null

I have a Wordpress site calling a .php file on our server using a shortcode. 我有一个Wordpress网站,使用短代码在我们的服务器上调用.php文件。 The goal is to return query parameters to a Wordpress form using hidden fields. 目的是使用隐藏字段将查询参数返回到Wordpress表单。

Here is the problem: $_GET['param'] doesn't seem to work for any key 'param'. 这是问题所在:$ _GET ['param']似乎不适用于任何键“ param”。 For example, I have the following code in my shortcode function: 例如,我的简码函数中包含以下代码:

ChromePhp::log('Test Output');
ChromePhp::log($_GET['test']);
ChromePhP::log($_SERVER['QUERY_STRING']);

I have installed a PHP logging plugin so I can see the PHP output from the Chrome javascript console. 我已经安装了PHP日志记录插件,因此可以从Chrome javascript控制台中查看PHP输出。 When I go to the URL mysite.com/properpage?test=testparam The output is: 当我转到URL mysite.com/properpage?test=testparam时,输出为:

Test Output
null
null

I'm not sure if it's relevant, but when I go to the url with the proper query params (?test=testparam), the url resets itself and clears the query params off the end. 我不确定是否相关,但是当我使用正确的查询参数(?test = testparam)进入url时,该URL会重置自身并最终清除查询参数。

I feel like I'm missing something simple. 我觉得我缺少一些简单的东西。 Or Wordpress may be blocking query params somewhere for this page so it clears the url? 还是Wordpress可能在该页面某处阻止了查询参数,因此它清除了URL?

As suggested by steve in the comment, I added the following to the functions.php file where my shortcode function is: 正如史蒂夫在评论中所建议的那样,我将以下内容添加到了我的简码功能所在的functions.php文件中:

add_action('init','wpse46108_register_param');
function wpse46108_register_param() { 
    global $wp; 
    $wp->add_query_var('test'); 
}

But

ChromePhp::log(get_query_var('test'));

still has empty output when I add the query param ?test=test. 当我添加查询参数?test = test时,输出仍然为空。

使用get_query_var()函数获取查询字符串变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM