Overview
Pre-filter values for a specific field type before default formatting.
Description
This filter is a field type specific version of acf/schema/format_value/pre. It allows you to pre-process values before ACF’s default formatting, but only for a specific field type.
The dynamic portion of the hook name, {field_type}, refers to the ACF field type.
Changelog
- Added in version 6.8.0
Parameters
apply_filters( 'acf/schema/format_value/pre/type={field_type}', $pre_value, $value, $field_object );
$pre_value(mixed) Pre-formatted value from previous filters, or null$value(mixed) The raw field value$field_object(array) The field object with settings
Return
(mixed|null) The pre-formatted value, or null to use default formatting.
Example
This example provides custom user formatting.
/**
* Custom user field formatting for Person schema.
*
* @param mixed $pre_value Pre-formatted value or null.
* @param mixed $value The raw value (user ID or array).
* @param array $field_object The field object.
* @return mixed Pre-formatted value or null.
*/
function my_acf_schema_format_user( $pre_value, $value, $field_object ) {
if ( ! $value ) {
return $pre_value;
}
$user_id = is_array( $value ) ? $value['ID'] : $value;
$user = get_userdata( $user_id );
if ( ! $user ) {
return $pre_value;
}
return array(
'@type' => 'Person',
'name' => $user->display_name,
'url' => get_author_posts_url( $user_id ),
'email' => $user->user_email,
'sameAs' => array(
get_user_meta( $user_id, 'twitter', true ),
get_user_meta( $user_id, 'linkedin', true ),
),
);
}
add_filter( 'acf/schema/format_value/pre/type=user', 'my_acf_schema_format_user', 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.
Related
- Filters: acf/schema/format_value/pre/name={field_name}
- Filters: acf/schema/format_value/type={field_type}
- Filters: acf/schema/format_value/name={field_name}
- Filters: acf/schema/format_value/pre
- Filters: acf/schema/format_value