Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
header('Location: /page-name/?var1=' 
. $_GET['var1'] . '&var2=' . $_GET['var2'] );
exit();

The result of the above code ends up redirecting the site to:

http://www.domain.com/page-name/?var1=val1&var2=val2`

I have a feeling Wordpress is cleaning the ampersand in the URL, but I don't at what point it would do that...

Edit: With Milo's direction, I modified the redirect code to look like this and it started working properly.

$url = '/page-name/';
$args =  array('var1'=>$_GET['var1'], 'var2' => $_GET['var2']);
$url = add_query_arg($args, $url);
wp_redirect($url);
exit();

I'd still like to know why the ampersand got converted to HTML in the first place.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

WordPress has API functions for doing both of these things- wp_redirect and add_query_arg.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.