Custom Fields
Re-Envisioned
Support MB Custom Table Showing decimal field leave extra zeros at the end. Any filter to solve that?

  • Creator
    Topic
  • #13386
    Resolved Camilo Mejia
    Participant

    I’m using MB Custom Table plugin and Elementor to display decimal fields. I used decimal(10, 2) when I created the table. The problem is that the numbers are displayed this way:

    80.53
    50.20
    20.00

    What I need is to display them without extra zeros at the end:

    80.53
    50.2
    20

    I tried with the filters get_post_metadata, rwmb_get_value and rwmb_meta without success, they didn’t dispatch with fields on a custom table. I also looked over the source code trying to find something useful without success.

    What can I do?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Author
    Replies
  • #13541
    Camilo Mejia
    Participant

    Any idea?

    #13543
    Anh Tran
    Keymaster

    Hi Camilo,

    As you set the data format for the table, can you please check the values stored in the database? If they’re saved in that format, then all plugins are working properly.

    #13701
    Camilo Mejia
    Participant

    Thanks for your help, but that’s not what I’m asking. What I need is to remove the extra leading zeros. With custom fields, we can use a filter to format the data as we need, but when using MB Custom Table, the filters aren’t triggered, so I don’t know how to format the data before showing to the user.

    #13705
    Anh Tran
    Keymaster

    Hi Camilo,

    I got it. So if you use the helper function rwmb_meta to get the value, you can use a filter to remove the extra zeros. This is the filter:

    apply_filters( 'rwmb_meta', $meta, $key, $args, $post_id );

    So you can do something like this:

    add_filter( 'rwmb_meta', function( $meta, $key, $args, $post_id ) {
        if ( 'your_field_id' === $key ) {
            $meta = your_function_remove_extra_zeros( $meta );
        }
        return $meta;
    }, 10, 4 );
    #13721
    Camilo Mejia
    Participant

    I tried that previously but isn’t working when used with Elementor dynamic fields.

    #13724
    Camilo Mejia
    Participant

    Looking at the code in meta-box/inc/functions.php I found the filter rwmb_the_value. That was the filter I was looking for. That filter is missing in the documentation.

    #13747
    Anh Tran
    Keymaster

    Glad that you found the filter. I missed it, too. Just added the docs for it. Thanks for your feedback!

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Newsletter

Subscribe to our newsletter to receive news and tutorials for Meta Box and WordPress.


grid gear info copy caret-up caret-down trash