WordPress.org

Codex

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

User:Abiralneupane/Function Reference/add term meta

This article is a ROUGH DRAFT. The author is still working on this document, so please do not edit this without the author's permission. The content within this article may not yet be verified or valid. This information is subject to change.

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.