add_term_meta() wordpress function and usage This text is not used because the data attribute has a value

add_term_meta() wordpress function and usage

Home / WordPress / WordPress Wiki / add_term_meta() wordpress function and usage

add_term_meta( int $term_id, string $meta_key, mixed $meta_value, bool $unique = false )
Adds metadata to a term.

Parameters

$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

(bool) (Optional) Whether the same key should not be added.

Default value: false

Return

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

Sample Usage

Usage

add_term_meta( $term_id, $meta_key, $meta_value, $unique );

Example
Adds a new custom field with a key name ‘my_term_key’ and value as ‘new_term’

add_term_meta( 12, "my_term_key" , 'new_term' );

 

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments