I am displaying numbers (non currency) via an advance custom field of paid_attendance
- however by default number fields in ACF do not include commas or decimals etc.
I would like for commas to be included when the numbers from paid_attendance
are output to the user on the front end. I am aware this can be done through the template file but I need to make it global via functions.php. I am probably way off, but below is the code I put together. Any help would be greatly appreciated.
// Return number with commas
function fix_number( $wpdb ) {
$number = get_field('paid_attendance');
number_format($number)."<br>";
}
add_action('fix_number');
EDIT Below is the fix and I have now got it working. Clearly and as Rick mentioned I was not using hooks properly. After reading deeper into the ACF docs and consulting other users on their forum, I was able to do what I need.
add_filter('acf/format_value/name=paid_attendance', 'fix_number', 20, 3);
function fix_number($value, $post_id, $field) {
$value = number_format($value);
return $value;
}
get_field
so if the field name ispaid_attendance
you can take the value and format as desired, which will then apply everywhere.