Home › Forums › General Issues › get_fields() – returns number fields as "2" instead of 2 › Reply To: get_fields() – returns number fields as "2" instead of 2
Yes, ACF returns number fields as strings.
Add a filter in functions.php
add_filter('acf/format_value/type=number', 'acf_number_str_to_number', 20, 3);
function acf_number_str_to_number($value, $post_id, $field) {
if (empty($value)) {
return $value;
}
$int = (int)$value;
$float = (float)$value;
if ($int == $float) {
return $int;
} else {
return $float;
}
}
You’ll need to contact the developers to change it any other way.
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.