acf_update_metadata()
Updates metadata in the database.
Хуки из функции
Возвращает
Int|true|false. Meta ID if the key didn't exist, true on successful update, false on failure.
Использование
acf_update_metadata( $post_id, $name, $value, $hidden );
- $post_id(int|строка)
- The post id.
- $name(строка)
- The meta name.
По умолчанию:'' - $value(разное)
- The meta value.
По умолчанию:'' - $hidden(true|false)
- If the meta is hidden (starts with an underscore).
По умолчанию:false
Список изменений
| С версии 5.2.3 | Введена. |
Код acf_update_metadata() acf update metadata ACF 6.4.2
function acf_update_metadata( $post_id = 0, $name = '', $value = '', $hidden = false ) {
// Allow filter to short-circuit logic.
$pre = apply_filters( 'acf/pre_update_metadata', null, $post_id, $name, $value, $hidden );
if ( $pre !== null ) {
return $pre;
}
// Decode $post_id for $type and $id.
$decoded = acf_decode_post_id( $post_id );
$id = $decoded['id'];
$type = $decoded['type'];
// Hidden meta uses an underscore prefix.
$prefix = $hidden ? '_' : '';
// Bail early if no $id (possible during new acf_form).
if ( ! $id ) {
return false;
}
// Determine CRUD function.
// - Relies on decoded post_id result to identify option or meta types.
// - Uses xxx_metadata(type) instead of xxx_type_meta() to bypass additional logic that could alter the ID.
if ( $type === 'option' ) {
$value = wp_unslash( $value );
$autoload = (bool) acf_get_setting( 'autoload' );
return update_option( "{$prefix}{$id}_{$name}", $value, $autoload );
} else {
return update_metadata( $type, $id, "{$prefix}{$name}", $value );
}
}