afb/value

Description

This filter allows you to modify the raw value of an ACF field before it is formatted and displayed in ACF Field Blocks.

Parameters

apply_filters( 'afb/value', $value, $field, $attr );
$value

(mixed)

The raw field value retrieved from ACF

$field

(array)

Complete field configuration array containing type, name, key, and other ACF field settings

$attr

(array)

Block attributes array containing block-specific settings

Modifiers

afb/value Applies to all fields.
afb/value/type={$type} Applies to all fields of a specific type.
afb/value/name={$name} Applies to all fields of a specific name.
afb/value/key={$key} Applies to all fields of a specific key.

Example

// Modify a text field value before formatting
add_filter( 'afb/value/name=first_name', function( $value, $field, $attr ) {
    // Example: Capitalize the first letter of a text field
    if ( 'text' === $field['type'] && is_string( $value ) ) {
        return ucfirst( $value );
    }
    return $value;
}, 10, 3 );Code language: PHP (php)