register_term_meta( string $taxonomy, string $meta_key, array $args )

Registers a meta key for terms.


Parameters Parameters

$taxonomy

(string) (Required) Taxonomy to register a meta key for. Pass an empty string to register the meta key across all existing taxonomies.

$meta_key

(string) (Required) The meta key to register.

$args

(array) (Required) Data used to describe the meta key when registered. See register_meta() for a list of supported arguments.


Top ↑

Return Return

(bool) True if the meta key was successfully registered, false if not.


Top ↑

Source Source

File: wp-includes/taxonomy.php

function register_term_meta( $taxonomy, $meta_key, array $args ) {
	$args['object_subtype'] = $taxonomy;

	return register_meta( 'term', $meta_key, $args );
}


Top ↑

Changelog Changelog

Changelog
Version Description
4.9.8 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by tzkmx

    Using this function with a specified schema makes its value available both in queries to get the value on the taxonomy and in the schema available through a request with OPTIONS method to the same endpoint.

    register_term_meta( 'replica', 'nice_field', array(
        'type' => 'string',
        'description' => 'a nice description',
        'single' => true,
        'show_in_rest' => array(
            'schema' => array(
                'type' => 'string',
                'format' => 'url',
                'context' => array( 'view', 'edit' ),
                'readonly' => true,
           )
        ),
    ) );
    

    Notes:
    – It is currently documented only for non scalar values (array and objects), but it’s valid using it for single values also.
    – It is available from version version 4.9.8

You must log in before being able to contribute a note or feedback.