WordPress.org

Codex

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

Function Reference/add term meta

Description

Adds a custom field (also called meta-data) to a specified term which could be related to any post type. A custom field is effectively a key–value pair.

Note that if the given key already exists among custom fields of the specified term, another custom field with the same key is added unless the $unique argument is set to true, in which case, no changes are made. If you want to update the value of an existing key, use the update_term_meta() function instead.

Usage

 <?php add_term_meta ($term_id$meta_key$meta_value$unique); ?> 

Parameters

$term_id
(integer) (required) The ID of the term to which a custom field should be added.
Default: None
$meta_key
(string) (required) The key of the custom field which should be added.
Default: None
$meta_value
(mixed) (required) The value of the custom field which should be added. If an array is given, it will be serialized into a string.
Default: None
$unique
(boolean) (optional) Whether or not you want the key to stay unique. When set to true, the custom field will not be added if the given key already exists among custom fields of the specified term.
Default: false

Return

(boolean|integer) 
On success, returns the ID of the inserted row, which validates to true. If the $unique argument was set to true and a custom field with the given key already exists, false is returned.

Change Log

Since: 4.4.0

Source File

add_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()

External Resources

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