Support

Account

Home Forums General Issues Formatting number fields using format_value Reply To: Formatting number fields using format_value

  • There are several alternatives

    If this was something I wanted to do on a large scale but did not want to have it run on all number fields I would add a custom setting to number fields https://www.advancedcustomfields.com/resources/adding-custom-settings-fields/

    Then I would create a format_value filter for all number fields that tested the new setting to see if the number should be formatted.

    Or, if there are only a few fields that should not be formatted then I would create the filter for all number fields like the one you have and I would check $field['key'] and not format those.

    Alternately, you could set up an array in your filter

    
    add_filter('acf/format_value/type=number', 'fix_number', 20, 3);
    function fix_number($value, $post_id, $field) {
      $keys = array(
        // list of field keys to format
        'field_XXXXXXX',
        'field_YYYYYYY',
        // etc...
      );
      if (in_array($field['key'], $keys)) {
        $value = number_format($value);
      }
      return $value;
    }