MB custom fields and WP Gridbuilder data issue on filter facet
Support › Meta Box AIO › MB custom fields and WP Gridbuilder data issue on filter facet
- This topic has 10 replies, 2 voices, and was last updated 2 years, 1 month ago by
Peter.
-
AuthorPosts
-
March 14, 2023 at 9:29 PM #41015
Bolo Duong
ParticipantVideo: 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; }
March 15, 2023 at 6:39 PM #41024Peter
ModeratorHello,
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
March 16, 2023 at 11:38 PM #41058Bolo Duong
ParticipantHi, 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
March 17, 2023 at 10:26 PM #41068Peter
ModeratorHello,
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/
March 17, 2023 at 11:21 PM #41070Bolo Duong
ParticipantHi 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
March 18, 2023 at 6:23 PM #41086Peter
ModeratorHello,
I do not see the sample post ID
123
is replaced when you use the code. According to your screen record, the post ID is424
. Can you please try to use the code again?$number = rwmb_meta( 'price', '', 424 );
Please check this screenshot https://monosnap.com/file/09JInc0QAK7R5gpdB4gNMSgZ1f3q0g
March 21, 2023 at 5:20 AM #41136Bolo Duong
ParticipantHi 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
March 21, 2023 at 6:48 PM #41144Peter
ModeratorHello,
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
March 22, 2023 at 10:10 PM #41174Bolo Duong
ParticipantHi 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
March 23, 2023 at 12:34 AM #41176Bolo Duong
ParticipantI 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 valueMarch 25, 2023 at 9:31 AM #41205Peter
ModeratorHello,
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. -
AuthorPosts
- You must be logged in to reply to this topic.