dongxuan2015 2013-10-09 14:23
浏览 22
已采纳

使用wordpress,如何使用永久链接传递变量

Here's the scenario:

A visitor to my site lands on restricted content. I provide a link to the membership options/signup page. Upon completion of signup, I want to redirect the user back to the page they were viewing.

The membership software I'm using (s2member) provides an success=(url) option, so I really just need to send the permalink of the page they were viewing to the signup page.

The restricted content uses a template file, in which I include a signup link (if they do not currently meet membership requirements). I'm trying to use the wpfunction: add_query_arg.

So, I have:

<a href="<?php echo add_query_arg( '$prev_page', get_permalink(), get_permalink( 67847 ) ); ?>">Sign Up</a>

And on the page this links to I see

http:///www.mysite.com/member-sign-up/?$prev_page=http://the-correct-permalink-pf-previous-page/

The problem is, on the memebership page, when I

var_dump( $prev_page ); 

it returns

null

Is this the correct method for sending a variable using a link?

  • 写回答

1条回答 默认 最新

  • drqyxkzbs21968684 2013-10-09 14:32
    关注

    Variables are not interpolated inside single quotes. Single quoted strings will display things almost completely as is. Change it to double quotes if you want the actual variable value to be used:

    <a href="<?php echo add_query_arg( "$prev_page", get_permalink(), 
    get_permalink( 67847 ) ); ?>">Sign Up</a>
    

    And now, you can access the query parameter in your membership page, like so:

    $var = $_GET['foo']; // where 'foo' == $prev_page
    echo $var;
    

    However, if you're actually trying to use the literal string $prev_page as your query parameter, you can simply do the following in your membership page:

    $_GET['$prev_page']; // note the single-quotes
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度