acf_field_taxonomy::update_valuepublicACF 3.6

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

Method of the class: acf_field_taxonomy{}

No Hooks.

Returns

Mixed. $value The modified value.

Usage

$acf_field_taxonomy = new acf_field_taxonomy();
$acf_field_taxonomy->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_taxonomy::update_value() code ACF 6.8.8

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

	if ( is_array( $value ) ) {
		$value = array_filter( $value );
	}

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

	// save_terms if enabled.
	if ( $field['save_terms'] ) {

		// vars
		$taxonomy = $field['taxonomy'];

		// force value to array.
		$term_ids = acf_get_array( $value );

		// convert to int.
		$term_ids = array_map( 'intval', $term_ids );

		// get existing term id's (from a previously saved field).
		$old_term_ids = isset( $this->save_post_terms[ $taxonomy ] ) ? $this->save_post_terms[ $taxonomy ] : array();

		// append
		$this->save_post_terms[ $taxonomy ] = array_merge( $old_term_ids, $term_ids );

		// if called directly from frontend update_field().
		if ( ! did_action( 'acf/save_post' ) ) {
			$this->save_post( $post_id );
			return $value;
		}
	}

	return $value;
}