Support

Account

Home Forums General Issues get_fields() – returns number fields as "2" instead of 2 Reply To: get_fields() – returns number fields as "2" instead of 2

  • Yes, ACF returns number fields as strings.

    Add a filter in functions.php

    
    add_filter('acf/format_value/type=number', 'acf_number_str_to_number', 20, 3);
    function acf_number_str_to_number($value, $post_id, $field) {
      if (empty($value)) {
        return $value;
      }
      $int = (int)$value;
      $float = (float)$value;
      if ($int == $float) {
        return $int;
      } else {
        return $float;
      }
    }
    

    You’ll need to contact the developers to change it any other way.