acf_field_relationship::update_valuepublicACF 3.6

Filters the field value before it is saved into the database.

Method of the class: acf_field_relationship{}

No Hooks.

Returns

Mixed. $value The modified value.

Usage

$acf_field_relationship = new acf_field_relationship();
$acf_field_relationship->update_value( $value, $post_id, $field );
$value(mixed) (required)
The value which will be saved in the database.
$post_id(int) (required)
The post_id of which the value will be saved.
$field(array) (required)
The field array holding all the field options.

Changelog

Since 3.6 Introduced.

acf_field_relationship::update_value() code ACF 6.8.8

public function update_value( $value, $post_id, $field ) {

	// Bail early if no value.
	if ( empty( $value ) ) {
		acf_update_bidirectional_values( array(), $post_id, $field );
		return $value;
	}

	// Format array of values.
	// - ensure each value is an id.
	// - Parse each id as string for SQL LIKE queries.
	if ( acf_is_sequential_array( $value ) ) {
		$value = array_map( 'acf_idval', $value );
		$value = array_map( 'strval', $value );

		// Parse single value for id.
	} else {
		$value = acf_idval( $value );
	}

	acf_update_bidirectional_values( acf_get_array( $value ), $post_id, $field );

	// Return value.
	return $value;
}