I am trying to add a ACF value to a function like:
function loginRedirect( $redirect_to, $request_redirect_to, $user ) {
$internStart = 'thisworks';
if ( is_a( $user, 'WP_User' ) && $user->has_cap( 'edit_posts' ) === false ) {
return home_url('/') . $internStart;
}
return $redirect_to;
}
add_filter( 'login_redirect', 'loginRedirect', 10, 3 );
So “thisworks” is added to the URL. But when I replace the variable with “get_field” (from an options field) it does not work:
function loginRedirect( $redirect_to, $request_redirect_to, $user ) {
$internStart = get_field('link_intern_start', 'option');
if ( is_a( $user, 'WP_User' ) && $user->has_cap( 'edit_posts' ) === false ) {
return home_url('/') . $internStart;
}
return $redirect_to;
}
add_filter( 'login_redirect', 'loginRedirect', 10, 3 );
What do I have to do to get the field?
What kind of field is link_intern_start? Looking at your code I can’t see any reason why it doesn’t work, unless it has something to do with what’s in the field.
Ummmmmm – just forgot it’s a post_object field 😉 – now it works, thank you john!