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.
Parameters
$term_idint
Term ID.
$meta_keystring
Metadata key.
$meta_valuemixed
Metadata value. Must be serializable if non-scalar.
$prev_valuemixedoptional
Previous value to check before updating. If specified, only update existing metadata entries with this value. Otherwise, update all entries. Default empty.Default: ''
Return
int|bool|WP_Error
Meta ID if the key didn't exist. true on successful update, false on failure or if the value passed to the function is the same as the one that is already in the database. WP_Error when term_id is ambiguous between taxonomies.
Uses · 4
wp_term_is_shared()Determines whether a term is shared between multiple taxonomies.
update_metadata()Updates metadata for the specified object. If no value already exists for the specified object ID and metadata key, the metadata will be added.
1471functionupdate_term_meta($term_id,$meta_key,$meta_value,$prev_value=''){1472if(wp_term_is_shared($term_id)){1473returnnewWP_Error('ambiguous_term_id',__('Term meta cannot be added to terms that are shared between taxonomies.'),$term_id);1474}14751476returnupdate_metadata('term',$term_id,$meta_key,$meta_value,$prev_value);1477}
History
Introduced in 4.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/taxonomy.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.