Skip Navigation

[Resolved] How do I format numeric field data in a content template

This support ticket is created 4 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 3 replies, has 2 voices.

Last updated by Beda 4 years, 2 months ago.

Assisted by: Beda.

Author
Posts
#1521775

I have a couple of numeric custom fields - such as price and mileage. They are numeric fields.

I would like to have them displayed with proper formatting such as 95,000 for mileage and $ 25,000 for price. I can't see a way to do this. I saw one response from someone else trying to do this and the suggestion was to create a shortcode or something in functions.php. I'd rather avoid that if possible.

When I go through the wizard to add a numeric field, it offers to provide a "format" attribute and gives a value of "FIELD_NAME: FIELD_VALUE". This implies that there might be other values I could put int he format attribute to format the number but I don't see any documentation on this.

#1522379

There is no "automatic" way to do this.

A numeric field is in its nature numeric, hence it will allow only numbers and dots.

What you'd have to do to format miles, prices, and other numeric data differently (it will also differ by country) is to create a single line field and enter the data as it should appear (with a comma, dot, or another separator).

Unfortunately, it is not possible to filter this elsehow with Toolset
Also, remember that you might need to use this in a filter, so having characters in there that are not numeric can lead to issues.

Better would be, to use the number field as is, always dot-separated, and add the unit in a second field or manually when inserting the value.

The format you refer to are only meant to control what's output for the field and its value - but there is no way to automatically intercept the type of value and convert that adequately.

#1523731

Thanks for the reply. It's unfortunate that you have a "format" option on the data but you don't really have any format characters to use with it. It looks like all you have are "FIELD_NAME" and FIELD_VALUE. Why not allow format characters - the printf characters that you find in other format templates - i.e. ##,###.## or whatever.

Your suggestion to just make this a text field has its own problems. People would then be able to enter the value in any way they want - with commas, without, with additional text, etc. Like you said, if it's a number make it a number. It's on the display side that we need options for formatting those numbers.

Anyway, I think I found a solution for this. It requires creating a shortcode but you guys have the Custom Code tab in Settings along with your documentation about it that makes this pretty simple.

Thanks.

#1526369

I'd suggest asking for the feature here https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
It is likely a complex implementation because there are many possible formats to follow, but if there are many users requesting this, our Product Management can consider such requests.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.