get_term_meta

Retrieves metadata for a term.

Description

get_term_meta( (int) $term_id, (string) $key = '', (bool) $single = false ); 

Parameters (3)

0. $term_id (int)
The term id.
1. $key — Optional. (string) => ''
The meta key to retrieve. If no key is provided, fetches all metadata for the term.
2. $single — Optional. (bool) => false
Whether to return a single value. If false, an array of all values matching the $term_id/'$key' pair will be returned. Default: false.

Usage

  1. if ( !function_exists( 'get_term_meta' ) ) { 
  2. require_once ABSPATH . WPINC . '/taxonomy.php'; 
  3.  
  4. // The term id. 
  5. $term_id = -1; 
  6.  
  7. // Optional. The meta key to retrieve. If no key is provided, fetches all metadata for the term. 
  8. $key = ''; 
  9.  
  10. // Whether to return a single value. If false, an array of all values matching the 
  11. // `$term_id`/`$key` pair will be returned. Default: false. 
  12. $single = false; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = get_term_meta($term_id, $key, $single); 
  16.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/taxonomy.php  
  1. function get_term_meta( $term_id, $key = '', $single = false ) { 
  2. // Bail if term meta table is not installed. 
  3. if ( get_option( 'db_version' ) < 34370 ) { 
  4. return false; 
  5.  
  6. return get_metadata( 'term', $term_id, $key, $single );