Redirect users based on custom field

I’m a novice at WordPress and i’m pretty sure what i’m looking for is really easy.
I have an issue with a function i made, which is :

function user_homepage() {

if ( is_user_logged_in() ) {
$args = array(
‘field’ => 25,
);
$user_homepage = bp_profile_field_data( $args );

if ($user_homepage == ‘Sports’) {
$redirect_to = home_url(‘/sports/’);
wp_redirect( $redirect_to );
exit;
}

else if ($user_homepage == ‘Tech’) {
$redirect_to = home_url(‘/tech/’);
wp_redirect( $redirect_to );
exit;
}

}
}
add_filter(‘login_redirect’,’user_homepage’,10,3);

As you can see i want to redirect my users based on a custom field i created in Buddypress. But more than that i don’t want them to simply be redirected after login, i want them to be redirect to this page when they go to the website homepage.

Any help would be greatly appreciated! Thanks!

Read more here:: Redirect users based on custom field

Leave a Reply

Your email address will not be published. Required fields are marked *