Archived topic
Automatic addition of commas to numbers in dynamic data
3 replies · Started by Takeru on April 3, 2022
Is there a way to automatically add commas to numbers in dynamic data?
For example, I would like to display 1,000 instead of 1000.
Hi Marumoro,
Thank you for reaching out to us here.
As an example, I created a custom Post Meta field mymetaname: https://share.getcloudapp.com/NQuNYoLy
I then created a Block Element with a Dynamic Headline Block as such: https://share.getcloudapp.com/04uEx2bJ
Now, I added this code through plugin Code Snippets:
add_filter( 'generate_dynamic_element_text', function( $my_post_meta, $block ){
if ( 'post-meta' === $block['attrs']['gpDynamicTextType'] && 'mymetaname' === $block['attrs']['gpDynamicTextCustomField']) {
$my_post_meta = number_format_i18n(floatval(get_post_meta(get_the_ID(),$block['attrs']['gpDynamicTextCustomField'])[0]));
}
return $my_post_meta;
},15,2);
Here it is working on my site: https://share.getcloudapp.com/Z4u7jKlo
Kindly replace mymetaname with your meta field name.
Hope this helps! :)
Perfect!
Thank you very much.
You’re welcome Marumoro! Glad that worked. :)