简体   繁体   English

WordPress网址参数不起作用

[英]WordPress url parameter is not working

What I am trying to do right now is really simple. 我现在想做的事情非常简单。 I want to send a parameter through the URL and then display it on a WordPress page. 我想通过URL发送参数,然后将其显示在WordPress页面上。 This is what I am currently doing: 这是我目前正在做的:

The URL I am putting in is www.domain.com/signin_page?message=yo 我输入的网址是www.domain.com/signin_page?message=yo

The shortcode I added to my functions.php file is: 我添加到functions.php文件中的简码是:

function write_login_message( $atts) {
  return "Message: " . $_GET['message'];
};
add_shortcode( 'write_message', 'write_login_message' );

The result is "Message: ". 结果是“消息:”。 Also, I get a notice: Undefined index: message in [...] . 另外,我得到一个通知: Undefined index: message in [...] I tried something I found in a discussion (making a plugin that sets a query variable) but that didn't work and now I'm stuck. 我尝试了在讨论中找到的内容(制作了一个用于设置查询变量的插件),但是该方法不起作用,现在我陷入了困境。 I'd appreciate any help. 我将不胜感激。

UPDATE: $_GET['message'] works on my production server. 更新:$ _GET ['message']在我的生产服务器上工作。 It isn't working in my test/sandbox server (they are basically the same thing though). 它在我的测试/沙盒服务器中不起作用(尽管它们基本上是同一件事)。 This narrows it down, but I am still not certain what the cause is. 这可以缩小范围,但是我仍然不确定原因是什么。 I can at least move on knowing that I can get it to work on my production server though. 我至少可以继续前进,尽管知道我可以在生产服务器上使用它。

Use this function to create the URL: 使用此函数创建URL:

add_query_arg( array(
    'key1' => 'value1',
    'key2' => 'value2',
), 'http://example.com' );

Hello you are creating short code and in the short code the parameters we need to define with the short code and you want to get it from url that is not possible as you are doing.Shortcode variables are passing like that 你好,你正在创建短代码,在短代码中,我们需要用短代码定义参数,并且你想从url中获取它,这是你做不到的。

[write_message message="yo"] and if you want to get it directly from URL then use $_GET['message'] [write_message message =“ yo”],如果您想直接从URL获取,请使用$ _GET ['message']

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

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