Hello!
Can you tell me how I can change the number format for a custom field which is displaying a number? Right now, it is showing straight numbers (100000) instead of formatted (100,000). I have found that I should add something in a php file, but I’m not sure which one.
The place I’m displaying the custom field is a custom post.
Thanks!
Hello, adding the code to the functions.php file didn’t work. Do you know what code I should add there?
The code I have to add should be added to the template file “single.php” or similar, but since this is a custom post, I’m not sure which file I should add it to. Do you know?
Hello!
By default, you can add, for example, “100.00” as a value in the post, and the custom field shortcode will display that number.
Check this guide: https://support.advancedcustomfields.com/forums/topic/insert-commas-into-acf-number-field/
I hope that helps you!
Thank you!
Thank you for pointing me that way! It works now. If this helps others, this is the solution that has worked for me: I have added this to the functions.php file (where my number fields are called field_name_1 and field_name_2):
$field_names = [‘field_name_1’, ‘field_name_2’];
foreach ($field_names as $field_name) {
add_filter(“acf/format_value/name={$field_name}”, ‘fix_number’, 20, 3);
}
function fix_number($value, $post_id, $field) {
if (is_numeric($value)) {
$value = number_format($value);
}
return $value;
}
