In my wordpress project I am have created template page where user can register. Now Problem I am facing is making user logged in after registration. I have created a user and after that I have tried to make the user log in using below code.
$creds = array();
$creds['user_login'] = $username;
$creds['user_password'] = $password;
$creds['remember'] = true;
$user = wp_signon( $creds, false );
I have also created a log in template to allow user loged in by using same above code but same issues occurs. Now problem I am facing is as soon as I moved to new page, I found user is not logged in.
I guess cookies are not getting saved. I have also tried using
wp_set_auth_cookie($user->ID,true);
But no success.
I cannot understand when we logged in using wp-admin then one can successfully logged in or if I am using wp_login_form() then that also works fine. Then wats is the problem by using above code.
Please help as I have to anyhow make user logged in after registration.