Support Forum
Support › Meta Box AIO › MB custom fields and WP Gridbuilder data issue on filter facet
Video: https://www.berrycast.com/conversations/c916d65d-4389-5638-8a50-b9426589ee3a
Code being used:
Sanitize Price Number Metabox
function custom_sanitize_number( $value ) {
// Format number, add separate comma
$value = number_format( (int) $value );
return $value;
}
Hello,
That is expected behavior. The number field only displays the raw number without formatting. You can format the number on the frontend only, don't use the sanitize callback function to modify the value format.
Or use a custom field type Multimask which is developed by an expert Meta Box user https://github.com/badabingbreda/field-text-multimask
Hi, Peter thanks for your soon answer. Do you have any code snippet I can use to format the number on the front? I used this one but seems it is not working
$number = rwmb_meta( 'price' );
// English notation
$english_format_number = number_format($number);
echo $english_format_number;
Can you help me with this
Thanks for your support
Hello,
That code outputs the number formatted as well on my demo site. You can try to pass the post ID to the third parameter of the helper function.
$number = rwmb_meta( 'price', '', 123 );
where 123 is the post ID. Please read more on the documentation https://docs.metabox.io/functions/rwmb-meta/
Hi Peter,
Thanks for your soon support. When Added the code it cratch my site, here is a video of what I'm trying to achieve, thanks a lot
https://www.berrycast.com/conversations/2dca75e0-08bc-5f5f-a95d-1ad9b819a4b4
Best Regards
Hello,
I do not see the sample post ID 123
is replaced when you use the code. According to your screen record, the post ID is 424
. Can you please try to use the code again?
$number = rwmb_meta( 'price', '', 424 );
Please check this screenshot https://monosnap.com/file/09JInc0QAK7R5gpdB4gNMSgZ1f3q0g
Hi Peter, thanks a lot for your support, now my site is not crashing but the codes seem not working, and not formatting my number price field.
Here I show you a video of my process. Again thanks =)
https://www.berrycast.com/conversations/a45db345-9f58-5c98-b0bf-176f5b89f0a1
Hello,
424 is the post ID and it is hard-coded, just for testing. If you want to get the price dynamically for the current post, you need to use a PHP code like get_queried_object_id() or get_the_ID().
But it might not work if you don't know what the current query is. If you are not familiar with coding, you can try to use the third-party plugin as I suggested above https://github.com/badabingbreda/field-text-multimask
Hi Peter,
Thanks for your support. I tried the multitask plugin, but it seems is not updated and is was causing some wrong behaviors at the meta box, like hiding some elements, etc.
I found this solution and seems it works
function format_my_number($atts) {
$num = $atts["value"];return number_format($num, 0, '.', ',');
}
add_shortcode("custom-number-format", "format_my_number");
But I need to add a shortcode and type the value. There is a way I can call my value, from the number field
[custom-number-format value=""]
Can you help guide me with some code I would really appreciate it
https://www.berrycast.com/conversations/783bd92c-92a4-5e1d-8075-fc7e1e599608
I have tried this code but doesn't output any change
$price = get_post_meta( get_the_ID(), 'price', true ); // Get the value of the custom field
$formatted_price = number_format( $price, 2, '.', ',' ); // Format the value with commas
echo $formatted_price; // Output the formatted value
Hello,
Please share your site credentials via this contact form https://metabox.io/contact/
and let me know where I can find the custom code added to your site to output the field value. I will take a look.