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.
- $terms = apply_filters( 'get_terms', $terms, $term_query_query_vars_taxonomy, $term_query_query_vars, $term_query );
- if ( !empty( $terms ) ) {
- // everything has led up to this point...
- }
- The following example is for adding a hook callback.
- // define the get_terms callback
- function filter_get_terms( $terms, $term_query_query_vars_taxonomy, $term_query_query_vars, $term_query ) {
- // make filter magic happen here...
- return $terms;
- };
- // add the filter
- add_filter( 'get_terms', 'filter_get_terms', 10, 4 );
- To remove a hook callback, use the example below.
- // remove the filter
- remove_filter( 'get_terms', 'filter_get_terms', 10, 4 );
Defined (1)
The filter is defined in the following location(s).
- /wp-includes/taxonomy.php
- return apply_filters( 'get_terms', $terms, $term_query->query_vars['taxonomy'], $term_query->query_vars, $term_query );