I have a Wordpress site calling a .php file on our server using a shortcode. The goal is to return query parameters to a Wordpress form using hidden fields.
Here is the problem: $_GET['param'] doesn't seem to work for any key '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. When I go to the URL mysite.com/properpage?test=testparam The output is:
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.
I feel like I'm missing something simple. Or Wordpress may be blocking query params somewhere for this page so it clears the url?
As suggested by steve in the comment, I added the following to the functions.php file where my shortcode function is:
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.
使用get_query_var()函数获取查询字符串变量
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.