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

I’m having a problem with this redirect after login. I added an extra field in the registration, then after that. If a user logins, I want to redirect that person to the specified URL based on the EXTRA FIELD he/she entered.

Thank you!

Related posts

Leave a Reply

1 comment

  1. Considering that you’re using update_usermeta( $user_id, $meta_key, $meta_value );, the following will do.

    I created a custom profile field named twitter and 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;
        }
    }