update_term_meta()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
update_term_meta( int $term_id, string $meta_key, mixed $meta_value, mixed $prev_value = '' ): int|bool|WP_Error
Описание
Используйте параметр $prev_value, чтобы различать поля метаданных с одинаковым ключом и одним и тем же ID термина.
Если поле метаданных для термина не существует, оно будет добавлено.
По историческим причинам на входе ожидается, что и ключ, и значение метаданных будут «экранированы обратными слэшами».
Оригинал (английский)
Use the $prev_value parameter to differentiate between meta fields with the same key and term ID.
If the meta field for the term does not exist, it will be added.
For historical reasons both the meta key and the meta value are expected to be “slashed” (slashes escaped) on input.
Параметры
$term_id
int
обязательный
$meta_key
string
обязательный
$meta_value
mixed
обязательный
$prev_value
mixed
необязательный
= ''
Возвращаемое значение
int|bool|WP_Error
Исходный код
wp-includes/taxonomy.php:1477
function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {
if ( wp_term_is_shared( $term_id ) ) {
return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
}
return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
}
История изменений
| Версия | Описание |
|---|---|
| 4.4.0 | Introduced. |

