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