Support

Account

Home Forums General Issues get_field returning null after update Reply To: get_field returning null after update

  • Here is a possible fix for those using get_field() for non ACF fields. This is untested. Most of it is pulled out of the function acf_get_metadata().

    
    add_filter('acf/load_value', 'get_meta_or_option_for_acf_get_field', 20, 3);
    function get_post_meta_for_acf_get_field($value, $post_id, $field) {
      if ($value !== NULL) {
        return $value;
      }
      $decoded = acf_decode_post_id( $post_id );
      $id      = $decoded['id'];
      $type    = $decoded['type'];
      if (!$id) {
        return $value;
      }
      $name = $field['name'];
      if ($type === 'option') {
        return get_option("{$id}_{$name}", NULL);
      } else {
        $meta = get_metadata($type, $id, $name, false);
        return isset($meta[0]) ? $meta[0] : NULL;
      }
    }