Tell us what you are trying to do?
I need to format a field of type number, as follows
2 digits, a hyphen, 8 digits, a hyphen, 1 digit
Example:
20-18047286-8
Is there any documentation that you are following?
https://toolset.com/forums/topic/output-format-for-a-custom-field-number/
But I can't figure out how it would be implemented in this case.
Is there a similar example that we can see?
I saw somewhere but I can't remember where, sorry!
What is the link to your site?
It's a local site
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
What if you try to use the following modified shortcode:
- You can add the following shortcode to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/
function func_show_formatted_number( $atts ) {
$atts = shortcode_atts( array(
'field' => ''
), $atts );
if(ctype_digit($field) && strlen($field) == 10) {
$number = substr($field,0,1) .'-'.
substr($field, 1, 8) .'-'.
substr($field, 9);
}
return $number ;
}
add_shortcode('show-formatted-number', 'func_show_formatted_number');
And you can use the above shortcode by adding the shortcode block or "Fields and Text" block as (if you are using Blocks):
[show-formatted-number field="[types field='your-field-slug' output='raw'][/types]"]
Where:
- replace 'your-field-slug' with your original field slug.
I tried but it doesn't work.
I think it could be because the number is 11 digits lengh, but it's just a guess.
The number 10 in the following line, is the total lengh of digits?
if(ctype_digit($field) && strlen($field) == 10) {
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
ahh yes - you spot that right.
What if you try to use the following code:
function func_show_formatted_number( $atts ) {
$atts = shortcode_atts( array(
'field' => ''
), $atts );
if(ctype_digit($field) && strlen($field) == 11) {
$number = substr($field,0,1) .'-'.
substr($field, 1, 8) .'-'.
substr($field, 9);
}
return $number ;
}
add_shortcode('show-formatted-number', 'func_show_formatted_number');