update_field()
This function will update a value in the database
No Hooks.
Returns
true|false.
Usage
update_field( $selector, $value, $post_id );
- $selector(string) (required)
- The field name or key.
- $value(mixed) (required)
- The value to save in the database.
- $post_id(mixed)
- The post_id of which the value is saved against.
Default:false
Changelog
| Since 3.1.9 | Introduced. |
update_field() update field code ACF 6.8.8
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 );
}