title: Use a $GET parameter from a URL, to create a new redirect URL (Wordpress)
body: <p>I am using a custom login page in Wordpress, and I installed a script in the functions.php that redirect to a custom "error login" page (adding parameters to the login URL), so it can display the errors in the same page instead of the native login page. </p>
  
  <p>But in some cases, this login page contains some parameters already, when someone is redirected there after trying to access a private page.</p>
  
  <p>For example :</p>
  
  <ul>
  <li><p>Regular case : They try to access : website.com/login. If there is an error when trying to login, my script redirect to website.com/login?login=empty, and they can try again.</p></li>
  <li><p>Problematic case : They try to access website.com/protected-page/private, they are automatically redirected to website.com/login?members=%2Fprotected-page%2Fprivate%2. If there is an error when trying to login, my script actualy redirect to website.com/login?login=empty (same as regular case), and what I'm trying to achieve, is to redirect to website.com/login?members=%2Fprotected-page%2Fprivate%2&amp;login=empty, when an error is made.</p></li>
  </ul>
  
  <p>Keeping this "?members" parameter in the URL allow the form to redirect to the previous page they were trying to access before, after a successful login. Otherwise with the regular case, they are redirected to the general dashboard.</p>
  
  <p>The script that actually manage the redirect when error is this one :</p>
  
  <p>add_action( 'authenticate', 'check_username_password', 1, 3);
  function check_username_password( $login, $username, $password ) {</p>
  
  <pre><code>$referrer = $_SERVER['HTTP_REFERER'];
  
  if( !empty( $referrer ) &amp;&amp; !strstr( $referrer,'wp-login' ) &amp;&amp; !strstr( $referrer,'wp-admin' ) ) { 
  if( $username == "" || $password == "" ){
      wp_redirect( get_permalink( 20 ) . "?login=empty" );
      exit;
  }
  }
  </code></pre>
  
  <p>So the important part here, that will create the error URL is : </p>
  
  <pre><code>wp_redirect( get_permalink( ID ) . "?login=empty" );
  </code></pre>
  
  <p>I can get my other UTL parameter with "$_GET["members"]", if I do an "echo $_GET["wlfrom"];" it displays successfully the parameter in the page. But even if it looks so simple, I don't manage to add this parameter to the URL. What I'v tried so far :</p>
  
  <pre><code>#1. wp_redirect( get_permalink( ID ) . "?members=" . $_GET["members"] . "?login=empty" );
  #2. wp_redirect( get_permalink( ID ) . "?members=" . echo $_GET["members"] . "?login=empty" );
  #3. $param = array('members');
  wp_redirect( get_permalink( ID ) . "?members=" . $param . "?login=empty" );
  //This one returns website.com/?members=array/?login=empty
  #4.$param = $_SERVER["PHP_SELF"];
  wp_redirect( $param . "?login=empty" );
  // This one I cannot use because it displays the native login URL, not my permalink, that's why I need to use "get_permalink" for the first part of the URL
  </code></pre>
  
  <p>And various other solutions too. I'm a newbie, so I can't find of other solutions to create this new URL based on the previous one, I'm not sure either if using GET is the way to go also.</p>
  
  <p>What should I fill up "wp_redirect" with in order to use the parameter from the current URL ?</p>
  
  <p>Thank you !</p>