update_field() ACF 3.1.9
This function will update a value in the database
Хуков нет.
Возвращает
(true/false).
Использование
update_field( $selector, $value, $post_id );
- (string)($selector) (обязательный)
- the field name or key
- (mixed)($value) (обязательный)
- the value to save in the database
- (mixed)($post_id) (обязательный)
- the post_id of which the value is saved against
Список изменений
С версии 3.1.9 | Введена. |
Код update_field() update field ACF 5.9.1
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 );
}