Home › Forums › General Issues › Change How Numbers Are Displayed
I am building a property website, so one of the fields is price. Naturally, with properties they have prices in the hundred of thousands or millions. I do not want to display it as 100000 but rather as 100 000 or 100,000. How will I go about doing this?
ChatGPT recommended me to go into the PHP’s number_format() function but I was wondering if there was another way?
If you’re not coding the templates then the only way to alter that will be use an acf/format_value filter for the field and the php number_format() function in that filter.
Sorry I’m still a bit if a noob when it comes to coding. Where would I insert this?
Hi All I have a similar problem and have tried the following in a snippet but cant get it to work, for the life of me I can’t find the error ! Any assistance would be appreciated:
add_shortcode(‘get_product_value’, ‘get_product_value’);
// function get_product_value($atts){
// extract(shortcode_atts(array(
// ‘post_id’ => NULL,
// ), $atts));
// if(!isset($atts[0])) return;
// // $field = esc_attr($atts[0]);
// $field = product_value;
// global $post;
// $post_id = (NULL === $post_id) ? $post->ID : $post_id;
// $post_value = get_post_meta($post_id, $field, true);
// $value = number_format($post_value, 2, “.”, “,”);
// return $value;
// }
function get_product_value($atts){
return “Atts = {$atts[0]}”;
extract(shortcode_atts(array(
‘post_id’ => NULL,
), $atts));
if(!isset($atts[0])) return;
$field = product_value;
global $post;
$post_id = $post->ID : $post_id;
$post_value = get_post_meta($post_id, $field, true);
$value = number_format($post_value, 2, “.”, “,”);
return $value;
}
You must be logged in to reply to this topic.
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.