update_field()ACF 3.1.9

This function will update a value in the database

Хуков нет.

Возвращает

true|false.

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

update_field( $selector, $value, $post_id );
$selector(строка) (обязательный)
The field name or key.
$value(разное) (обязательный)
The value to save in the database.
$post_id(разное)
The post_id of which the value is saved against.
По умолчанию: false

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

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

Код update_field() ACF 6.4.2

function update_field( $selector, $value, $post_id = false ) {

	// filter post_id
	$post_id = acf_get_valid_post_id( $post_id );

	// get field
	$field = acf_maybe_get_field( $selector, $post_id, false );

	// create dummy field
	if ( ! $field ) {
		$field = acf_get_valid_field(
			array(
				'name' => $selector,
				'key'  => '',
				'type' => '',
			)
		);
	}

	// save
	return acf_update_value( $value, $post_id, $field );
}