Support

Account

Home Forums General Issues Add ACF field value to function

Solved

Add ACF field value to function

  • 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!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Add ACF field value to function’ is closed to new replies.