get_terms

Filters the found terms.

Description

apply_filters( 'get_terms', (array) $terms, (array) $term_query_query_vars_taxonomy, (array) $term_query_query_vars, (WP_Term_Query) $term_query ); 

Parameters (4)

0. $terms (array)
Array of found terms.
1. $term_query_query_vars_taxonomy (array)
The term query query vars taxonomy.
2. $term_query_query_vars (array)
An array of get_terms() arguments.
3. $term_query (WP_Term_Query)
The WP_Term_Query object.

Usage

To run the hook, copy the example below.
  1. $terms = apply_filters( 'get_terms', $terms, $term_query_query_vars_taxonomy, $term_query_query_vars, $term_query ); 
  2.  
  3. if ( !empty( $terms ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the get_terms callback 
  2. function filter_get_terms( $terms, $term_query_query_vars_taxonomy, $term_query_query_vars, $term_query ) { 
  3. // make filter magic happen here... 
  4. return $terms
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'get_terms', 'filter_get_terms', 10, 4 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'get_terms', 'filter_get_terms', 10, 4 ); 

Defined (1)

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

/wp-includes/taxonomy.php  
  1. return apply_filters( 'get_terms', $terms, $term_query->query_vars['taxonomy'], $term_query->query_vars, $term_query );