I have created a new user role named student_role I want to redirect the user with this role to form page(which I created from wp front end) when he logs in.
I tried peter login redirect plugin but failed.
I have created a new user role named student_role I want to redirect the user with this role to form page(which I created from wp front end) when he logs in.
I tried peter login redirect plugin but failed.
You must be logged in to post a comment.
Try this :
Explanation
If you look at the codex, you will find that
wp_login
provides two parameter: 1)$user_login
which will return a string and 2)$user
will return an object containing all the details.But you need to make sure that you also pass priority to that parameters otherwise It will give you an error.
If you want to see what data are into that parameter, you can run below code for learning purpose only.
Make sure you delete above code from
functions.php
after checking what data it containsSo as you can
$user
object contains roles which shows current logged in user’s role. So I simple checked thatif($user->roles[0] === 'student_role')
if current logged in user is havingstudent_role
thenwp_redirect('Your page link goes here')
redirect them to some page.Let me know if you have any doubt.