acf/update_value │ filter-hook │ ACF 5.0.0

Allows you to modify an ACF custom field value before it is saved to the database.

This filter is called when an ACF field value is updated and makes it possible to modify the value being saved. It works both when saving a post and when saving custom fields through other interfaces.

The filter can be applied globally to all fields or to a specific field, a specific field type, or fields with a particular name.

Filter variations

This filter supports modifiers that create equivalent filters applied only to particular fields.

The following filter names are available:

  • acf/update_value — the current filter, applied to all fields.
  • acf/update_value/type={$type} — applied to all fields of a specific type, such as text, image, or repeater.
  • acf/update_value/name={$name} — applied to all fields with a specific name.
  • acf/update_value/key={$key} — applied to all fields with a specific key.

These hook variations are registered by acf_add_filter_variations(). See includes/acf-value-functions.php:

Usage

add_filter( 'acf/update_value', 'wp_kama_acf_update_value_filter', 10, 4 );

/**
 * Function for `acf/update_value` filter-hook.
 * 
 * @param mixed  $value    The value to update.
 * @param string $post_id  The post ID for this value.
 * @param array  $field    The field array.
 * @param mixed  $original The original value before modification.
 *
 * @return mixed
 */
function wp_kama_acf_update_value_filter( $value, $post_id, $field, $original ){
	// filter...
	return $value;
}
$value(mixed)
New field value to save.
$post_id(string|int)
ID of the object (post, user, term, and so on) to which the field belongs.
$field(array)
Array of ACF field settings.
$original(mixed)
Original field value before any modifications.

Examples

#1 Replace text in all field values

Applies the filter to all fields and replaces the string "Old Company Name" with "New Company Name" when the value is a string.

add_filter( 'acf/update_value', 'my_acf_update_value', 10, 4 );

function my_acf_update_value( $value, $post_id, $field, $original ) {
	if ( is_string( $value ) ) {
		$value = str_replace( 'Old Company Name', 'New Company Name', $value );
	}
	return $value;
}

Hook variations:

// Apply only to `textarea` fields.
add_filter( 'acf/update_value/type=textarea', 'my_acf_update_value', 10, 4 );

// Apply only to fields named `hero_text`.
add_filter( 'acf/update_value/name=hero_text', 'my_acf_update_value', 10, 4 );

// Apply only to the field with the `field_123abcf` key.
add_filter( 'acf/update_value/key=field_123abcf', 'my_acf_update_value', 10, 4 );

Changelog

Since 5.0.0 Introduced.

Where the hook is called

acf_update_value()
acf/update_value
acf/includes/acf-value-functions.php 244
$value = apply_filters( 'acf/update_value', $value, $post_id, $field, $value );

Where the hook is used in Advanced Custom Fields PRO

Usage not found.