get_term_meta() – get value from taxonomy meta field

This function is used if you need to get some taxonomy meta data. This function works the same as the get_post_meta() function.

get_term_meta ( $term_id, $key, $single )

(number) (required) we specify the taxonomy element ID

(string) (optional) we specify the name of the key of the meta field. If the key is not specified, it will display an array of all meta fields of this taxonomy. Default “.

(logical) (optional) can be:

false – returns all values of arbitrary fields with the specified key as an array, this is what I mean:

true – returns the very first value of an arbitrary field with the specified key as a string;


if $single is false, then returns an array of values for the specified meta field.
if $single is true, then returns the value of the specified meta field (the very first).

Example of use:

$termini = get_terms( 'category', 'hide_empty=-1' );
foreach( $termini as $termin ){
echo $termin_meta = get_term_meta( $termin->term_id, 'my_meta_field', true );

In this example, we passed through the cycle all taxonomies (posts headings) and derived the result for each rubric (category). To get data about taxonomy elements, we used the get_terms() function.

The most important thing! Do not forget to check that your taxonomy has created meta fields, otherwise you will get an empty array. You can add data using simple functions add_term_meta() or update_term_meta().


May, 31 2019 at 18:24

I create web projects, develop, optimize and promote websites. If you have any ideas or want to suggest something, then write to me and my team.

Top ↑

Leave a Reply