acf/schema/format_value/type={field_type}

Last updated Mar 31, 2026

Overview

Filter formatted values for a specific field type.

Description

This filter is a field type specific version of acf/schema/format_value. It allows you to modify formatted values only for a specific ACF field type.

The dynamic portion of the hook name, {field_type}, refers to the ACF field type (e.g., text, number, image).

Changelog

  • Added in version 6.8.0

Parameters

apply_filters( 'acf/schema/format_value/type={field_type}', $formatted_value, $value, $field_object );
  • $formatted_value (mixed) The value after default formatting
  • $value (mixed) The original raw field value
  • $field_object (array) The field object with settings

Return

(mixed) The modified formatted value.

Example

This example ensures all number fields output as floats.

/**
 * Format numbers as floats.
 *
 * @param mixed $formatted_value The formatted value.
 * @param mixed $value           The raw value.
 * @param array $field_object    The field object.
 * @return mixed Modified value.
 */
function my_acf_schema_format_numbers( $formatted_value, $value, $field_object ) {
    return (float) $formatted_value;
}
add_filter( 'acf/schema/format_value/type=number', 'my_acf_schema_format_numbers', 10, 3 );

This example customizes image output format.

/**
 * Custom image formatting with additional metadata.
 *
 * @param mixed $formatted_value The formatted value.
 * @param mixed $value           The raw value (attachment ID).
 * @param array $field_object    The field object.
 * @return mixed Modified value.
 */
function my_acf_schema_format_images( $formatted_value, $value, $field_object ) {
    if ( ! is_array( $formatted_value ) || ! isset( $formatted_value['@type'] ) ) {
        return $formatted_value;
    }

    // Add license info to all images
    $formatted_value['license'] = 'https://creativecommons.org/licenses/by/4.0/';

    // Add content URL
    if ( isset( $formatted_value['url'] ) ) {
        $formatted_value['contentUrl'] = $formatted_value['url'];
    }

    return $formatted_value;
}
add_filter( 'acf/schema/format_value/type=image', 'my_acf_schema_format_images', 10, 3 );
Supercharge Your Website With Premium Features Using ACF PRO

Speed up your workflow and unlock features to better develop websites using ACF Blocks and Options Pages, with the Flexible Content, Repeater, Clone, Gallery Fields & More.

Explore Features View Pricing

PRO Features
ACF Blocks
Options Pages
PRO Fields
Repeater
Flexible Content
Gallery
Clone

Related