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

使用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?

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