Support

Account

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;
    }