acf_field_select::update_valuepublicACF 3.6

Filters the $value before it is updated in the db.

Method of the class: acf_field_select{}

No Hooks.

Returns

mixed.

Usage

$acf_field_select = new acf_field_select();
$acf_field_select->update_value( $value, $post_id, $field );
$value(mixed) (required)
The value which will be saved in the database.
$post_id(int|string) (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_select::update_value() code ACF 6.8.8

public function update_value( $value, $post_id, $field ) {
	// Bail early if no value.
	if ( empty( $value ) ) {
		return $value;
	}

	// Format array of values.
	// - Parse each value as string for SQL LIKE queries.
	if ( is_array( $value ) ) {
		$value = array_map( 'strval', $value );
	}

	// Save custom options back to the field definition if configured.
	if ( ! empty( $field['save_options'] ) && is_array( $value ) ) {
		// Get the raw field, using the ID if present or the key otherwise (i.e. when using JSON).
		$selector = $field['ID'] ? $field['ID'] : $field['key'];
		$field    = acf_get_field( $selector );

		// Bail if we don't have a valid field or field ID (JSON only).
		if ( empty( $field['ID'] ) ) {
			return $value;
		}

		$this->append_user_choices_to_field( $value, $post_id, $field );
	}

	return $value;
}