WordPress at a glance

add_term_meta() WP 1.0

Adds metadata to a term.

No Hooks.

Return

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

Usage

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.
$unique(true/false)
Whether the same key should not be added.
Default: false

Changelog

Since 4.4.0 Introduced.

Code of add_term_meta() WP 5.5.1

<?php
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 );
}

From tag: Metadatas (any)

No comments
    Log In . Register