WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/update term meta

Description

The function update_term_meta() updates the value of an existing meta key (custom field) for the specified term.

This may be used in place of add_term_meta() function. The first thing this function will do is make sure that $meta_key already exists on $term_id. If it does not, add_term_meta($term_id, $meta_key, $meta_value) is called instead and its result is returned.

Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure. It also returns false if the value submitted is the same as the value that is already in the database.

Usage

 <?php update_term_meta($term_id$meta_key$meta_value$prev_value); ?> 

Parameters

$term
(integer) (required) The ID of the term which contains the field you will edit.
Default: None
$meta_key
(string) (required) The key of the custom field you will edit. (this should be raw as opposed to sanitized for database queries)
Default: None
$meta_value
(mixed) (required) The new value of the custom field. A passed array will be serialized into a string.(this should be raw as opposed to sanitized for database queries)
Default: None
$prev_value
(mixed) (optional) The old value of the custom field you wish to change. This is to differentiate between several fields with the same key. If omitted, and there are multiple rows for this term and meta key, all meta values will be updated.
Default: Empty

Return Values

(mixed) 
Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure. NOTE: If the meta_value passed to this function is the same as the value that is already in the database, this function returns false.

Change Log

Since: 4.4.0

Source File

update_term_meta() is located in wp-includes/taxonomy.php.

Related

add_term_meta(), delete_term_meta(), get_term_meta(), update_term_meta(), update_termmeta_cache()

See also index of Function Reference and index of Template Tags.