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 that doesn't work :
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);
Updated version, still doesn't work
function redirect_user_homepage() {
global $bp;
if ( is_user_logged_in() && is_front_page() ) {
$args = array(
'field' => 25,
'user_id' => bp_loggedin_user_id()
);
$user_homepage = bp_profile_field_data($args);
if ($user_homepage == "All") {
wp_redirect( home_url() );
exit;
}
elseif ($user_homepage == "Sports") {
wp_redirect( home_url('/sports/') );
exit;
}
elseif ($user_homepage == "Tech") {
wp_redirect( home_url('/tech/') );
exit;
}
}
}
add_action( 'template_redirect', 'redirect_user_homepage');
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!