Home Forums Bug Reports acf/format_value doesn't work reliable


acf/format_value doesn't work reliable

    • jsvegas

    • November 25, 2019 at 7:46 pm

    I use the filter ‘acf/format_value’ to change fields before output.

    Unfortunately it doesn’t work reliable. For testing I use error_log. With some fields it works, with some not. As I understand it, there should be an error_log for each get_field on the site ($format_value = true).

    add_filter('acf/format_value', 'e1_format_all', 10, 3);
    function e1_format_all($value, $post_id, $field)
        if (strpos($field['name'], 'returns_') !== false) {
            $value = e1_calculate_eur_returns($field['name'], $post_id, $value);
            $value = number_format_i18n($value * 100, 2) . '%';
        return $value;
  • What type of field is it not working with?

    Is the filter not called? or is it not formatting the way you want it to?

    Does the field you are trying to format have a value on the post where you are trying to format it?

    • jsvegas

    • November 27, 2019 at 5:23 am

    It occurred with different types, in the most recent case it‘s a number field.

    It‘s not called and thats why it’s not formatted. The error_log simply doesn’t appear (in some unexplainable cases).

    Yes it has a value. Get_field gets a value (unformatted)

  • Is the field a sub field in a repeater, flexible content or clone field?

    • jsvegas

    • November 27, 2019 at 6:42 am

    It‘s part of a group. Sorry that I forgot to mention that.

  • Going to be honest, I don’t know why this is not running, because you are using

    add_filter('acf/format_value', 'e1_format_all', 10, 3);

    which should be run on every field that is formatted.

    The only reason that I know of for the filter not to be called is if you use

    get_field('field_name', false, false)

    the 3rd argument tells ACF not to format the value, and in this case no formatting filters are run.

    • jsvegas

    • November 28, 2019 at 6:26 pm

    Ok, but thank you anyways!

    I know the 3rd argument and it’s not the reason… Maybe it has something to do with Elementor / Elementor Pro which I am using…

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.