Home › Forums › ACF PRO › Error getting option even though get_field function exists › Reply To: Error getting option even though get_field function exists
You are probably creating an infinite loop with your filter. More than likely your call to get_field() is inadvertently causing your filter to be called again, but this is just a guess assuming that everything runs fine when you remove your filter.
What you need to do is remove your filter at the top of the filter and than add it back in before returning.
add_filter('determine_current_user', 'set_user');
function set_user($user_id)
{
remove_filter('determine_current_user', 'set_user');
if (function_exists('get_field')) {
$user = get_field('user_id', 'option');
} else {
$user = 0;
}
add_filter('determine_current_user', 'set_user');
return $user;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.