How to redirect users after login based on wp user meta-key?

I had a problem with this redirect after login. I added an additional field to the registration, after which. If the user logs in, I want to redirect this person to the specified URL based on the EXTRA FIELD that he entered.

Thank!

+3
source share
1 answer

Given what you are using update_usermeta( $user_id, $meta_key, $meta_value );, do the following.

I created a custom profile field with a name twitterand applied this hook to wp_login:

add_action( 'wp_login', 'redirect_login_so_21774306', 10, 2 );

function redirect_login_so_21774306( $user_login, $user )
{
    $twitter = get_the_author_meta( 'twitter', $user->data->ID );
    if( $twitter )
    {
        wp_redirect( site_url( "custom-post/?twitter=$twitter", 'http' ), 301 );
        exit;
    }
}
0
source

All Articles