0

I had to add a query on the end of my URL, like this:

http://www.somewordpressite.com/?page_id=57?login=failed

Now I need to check if '?login=failed' exists, so I can load the correct piece of a template.

I have tried a bunch of variations, but I just can't seem to grab it.

<?php

$checkurlquery[] = $_SERVER['QUERY_STRING'];
//echo json_encode($_GET, JSON_HEX_TAG);

foreach($checkurlquery as $key => $v){
  $dice = $checkurlquery[$key];
  echo ($dice);
} 
?>

Result: page_id=57?login=failed

Ultimately, I'm just trying to get to here:

if ( //LOGIN failed )) {
        get_template_part( 'login', 'failed' );
} else {
    get_template_part( 'login', 'form' );
}

How can I check for login=failed, so I can use it to load the right template part? Thanks.

Edit: Yes, I was able to change the URL, so it can be: http://www.somewordpressite.com/?page_id=57&login=failed, but it created an issue. Because Wordpress uses that '?', then if I am on the home page, and fail at login, I get a 404 error:

This URL is ok and grabs the index page:
www.site.com/?login=failed

This URL is a 404 error:
www.site.com/&login=failed

Edit: Here is the updated function necessary in Wordpress functions.php: Redirect after login, Wordpress URLs

Then in header.php (or place of your choice), add:

 <?php

if(isset($_GET['login']) === true and $_GET['login'] === 'failed')
{
   get_template_part( 'login', 'failed' );
} else {
   get_template_part( 'login', 'form' );
}
?>
1
  • Your query is malformed ... there should be only one ? Commented Aug 17, 2012 at 5:23

2 Answers 2

2

Can't you use a normal query string

http://www.somewordpressite.com/?page_id=57&login=failed

and use something like

if ($_GET['login'] == 'failed') {
        get_template_part( 'login', 'failed' );
} else {
    get_template_part( 'login', 'form' );
}
Sign up to request clarification or add additional context in comments.

2 Comments

it's better to check with isset($_GET['login']) 1st or else you will get some funny warning.
@YouQi It's called an E_NOTICE and it is an error type of undefined index
0

if you want to test for the query string parameters existence

if(isset($_GET['LOGIN']) === true)
{
 // it has at least been set
}

in addition if you also want to test for a specific value

if(isset($_GET['login']) === true and $_GET['login'] === 'failed')
{
 // it been set and it equals a specific value
}

6 Comments

What is the meaning of 3 equal signs, please? I hadn't seen that before.
Its a strict check if this equals exactly true and not a "truthy" value (like "1" or "string" which will be true too with 2 signs) but here its unnecessary, because isset only returns true or false, you can rely on that.
Edited my post, I checked and rechecked whether I could change my URL, and it creates an error because of how Wordpress is setup (I think), but there may be a fix that could be added if anyone knows Wordpress.
Should I ask that in a separate question? It's a common Wordpress issue, dissatisfaction with the login process.
you might want get_query_var('login') instead of $_GET['login'] then
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.