Reputation: 581
I have ACF (Advanced Custom Fields) on my WordPress website and am trying to add a comma every 3rd place (1,000) instead of (1000) using PHP. I am utilizing the code below but when I save it the website breaks (critical error). I suspect this is my own error (novice) and hope someone can help me find out what I'm doing incorrectly or what I could try.
`
add_filter('acf/format_value/name=number_of_supporters', 'fix_number', 20, 3);
function fix_number($value, $post_id, $field) {
$value = number_format($value);
return $value;
}
`
The website URL is https://coregiving.org and it leverages the Oxygen builder (if it's relevant).
Thank you!
-I was expecting the code I added to my website would add a comma delimiter-
Upvotes: 0
Views: 987
Reputation: 111
Assuming the ACF field type is number
, ACF is going to return the raw number. Rather than trying to filter the value, you could instead use the number format function in the template where you are going to display it. Something like this:
echo number_format( get_field( 'number_of_supporters' ) );
Upvotes: 1