I need to restrict access to certain frontend pages, based on a user_meta field.
All works fine, except when the user is already logged in but with the wrong credentials. In that situation I would want them to be redirected to the login form (with a message encouraging them to logout and login again with suitable credentials - I can do that bit).
Instead, the user ends up with the "redirecting in a way that will never complete" message.
I think the only bit of my code that's relevant to this issue is:
if(!$user_is_approved) {
wp_redirect(wp_login_url( get_permalink() ));
exit;
}
What's the best way of achieving this?