WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
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
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

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.