Support

Account

Home Forums General Issues format_value is inconsistent (or I just don't get it…)

Solved

format_value is inconsistent (or I just don't get it…)

  • Hi, I’m having some issues with the acf/format_value filter. I’m not sure if I’m applying it incorrectly or if there’s a bug with it though.

    Essentially, I’m running the filter to adjust some ACF field content before it’s displayed on the frontend. I want to run a check for specific keywords in any text field types (text, textarea or WYSIWYG).

    This is my code for doing so (in my theme’s functions.php):

    function aa_output_journey( $value, $post_id, $field ) {
    
        // Only apply this logic to text, textarea or wysiwyg fields.
        if ( 'text' === $field['type'] || 'textarea' === $field['type'] || 'wysiwyg' === $field['type'] ) {
    
            /* ETC */
    
        }
    
        return $value;
    
    }
    
    add_filter( 'acf/format_value', 'aa_output_journey', 30, 3 );

    Problem is, it’s not applied consistently to all my ACF fields. It seems to work fine for fields that are within a flexible content layout, but not for fields that are on the top level of a field group.

    To test, I commented out all of the code in the filter function and added a var_dump( $field ) to show me all the field content. The result was a page full of var_dump content, with almost all of the fields in my template, but some of them were still missing – there was no output for them at all, leading me to believe that format_value was not being applied to those fields.

    Screenshot of my custom field setup

    This is my custom field setup. The content field at the bottom of the screenshot is a clone of a flexible content field that is specified in another field group – mostly for ease of editing. All of the fields within the content field seem to get the format_value filter applied correctly.

    It’s the other fields in this field group that I’m concerned about – the preview_text and full_text fields. They’re the ones that seem to be bypassed entirely.

    Am I missing something, am I applying it wrong? Please let me know if I can provide any further information that would help.

    Cheers!

  • TL;DR: I’m using the format_value filter to adjust some field values before they’re displayed, but the filter does not seem to be applied to all fields and I don’t understand why.

  • I’ve figured it out.

    I’m building my theme using Timber and I didn’t realise that simply calling a field value by using {{ post.preview_text }} doesn’t apply preprocessing (or filters apparently) to the value. Instead you need to call {{ post.meta('preview_text') }}.

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

The topic ‘format_value is inconsistent (or I just don't get it…)’ is closed to new replies.