0
votes

I need to pass GET variable after user logs in /wp-login.php wordpress login.

Here's what I've managed to figure out so far - Login redirect reference: https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect

So I want link like http://somewebsite.com/wp-login.php?redirect_to=http://somewebsite.com/page/&variable=1 cause user that logs in to be redirected to http://somewebsite.com/page/?variable=1 but it drops the GET variable cause it isn't part of redirect_to

Perhaps someone could nudge me further in right direction? Maybe something with URL encoding?

2
Have you tried urlencoding the passed url resulting in & -> %26 etc.?FMK
Yeah I tried that - unless I'm doing something wrong it doesn't work. For example: somewebsite.com/wp-login.php?redirect_to=http%3A%2F%2Fsomewebsite.com%2Fpage recirects correctly but when I try to use it like this: somewebsite.com/wp-login.php?redirect_to=http%3A%2F%2Fsomewebsite.com%2Fpage%26cm=1 it goes to homepage instead and doesn't pass GET variableGreg Viv

2 Answers

1
votes

Ahh I just realized it was URL encoding issue. Below is full correct URL

http://somewebsite.com/wp-login.php?redirect_to=http%3A%2F%2Fsomewebsite.com%2Fpage%2F%3Fvariable%3D1

Turns out I had all the right answers but struggled with execution

0
votes
add_filter( 'login_redirect', function( $url, $query, $user ) {
    return home_url() . '?foo=bar';
}, 10, 3 );

?foo=bar will be passed to your final location.

You can dump $url & $query to see the data you get while logging in