acf_field_taxonomy::update_valuepublicACF 3.6

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

Метод класса: acf_field_taxonomy{}

Хуков нет.

Возвращает

Разное. $value The modified value.

Использование

$acf_field_taxonomy = new acf_field_taxonomy();
$acf_field_taxonomy->update_value( $value, $post_id, $field );
$value(разное) (обязательный)
The value which will be saved in the database.
$post_id(int) (обязательный)
The post_id of which the value will be saved.
$field(массив) (обязательный)
The field array holding all the field options.

Список изменений

С версии 3.6 Введена.

Код acf_field_taxonomy::update_value() ACF 6.4.2

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;
}