add_term_meta()WP 4.4.0

Adds metadata to a term.

No Hooks.


Int|false|WP_Error. Meta ID on success, false on failure. WP_Error when term_id is ambiguous between taxonomies.


add_term_meta( $term_id, $meta_key, $meta_value, $unique );
$term_id(int) (required)
Term ID.
$meta_key(string) (required)
Metadata name.
$meta_value(mixed) (required)
Metadata value. Must be serializable if non-scalar.
Whether the same key should not be added.
Default: false


Since 4.4.0 Introduced.

Code of add_term_meta() WP 5.9.3

function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) {
	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 add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );