Function Reference/get terms
Description
Retrieve the terms in taxonomy or list of taxonomies.
Usage
<?php get_terms( $taxonomies, $args ) ?>
Parameters
- $taxonomies
- (string|array) (required) The taxonomies to retrieve terms from.
- Default: None
- $args
- (string|array) (optional) Change what is returned.
- Default: array
Possible Arguments
- orderby
- (string)
- name - Default
- count
- none - will use
term_id.
- order
- (string)
- hide_empty
- (boolean) Whether to return empty $terms.
- 1 (true) - Default
- 0 (false)
- fields
- (string)
- all - returns an array of term objects - Default
- ids - returns an array of integers
- names - returns an array of strings
- slug
- (string) Any terms that has this value. Default is empty string.
- hierarchical
- (boolean) Whether to return hierarchical taxonomy or not.
- 1 (true) - Default
- 0 (false)
- name__like
- (string) Default is empty string.
- pad_counts
- (boolean) If true, count all of the children along with the $terms.
- 1 (true)
- 0 (false) - Default
- get
- (string) Default is nothing . Allow for overwriting 'hide_empty' and 'child_of', which can be done by setting the value to 'all'.
- child_of
- Get all descendents of this term. Default is 0.
- parent
- (integer|string) Get direct children of this term (only terms who's explicit parent is this value). If 0 is passed, only top-level terms are returned. Default is an empty string.
NOTE: Arguments are passed in the format used by wp_parse_args(). e.g.
Examples
$myterms = get_terms('category', 'orderby=count&hide_empty=0');
Details
You can fully inject any customizations to the query before it is sent, as well as control the output with a filter.
The 'get_terms' filter will be called when the cache has the term and will pass the found term along with the array of $taxonomies and array of $args.
This filter is also called before the array of terms is passed and will pass the array of terms, along with the $taxonomies and $args.
The 'list_terms_exclusions' filter passes the compiled exclusions along with the $args.
Source File
get_terms() is located in wp-includes/taxonomy.php.
Related
is_term,
get_term,
get_term_by,
get_term_children,
get_terms,
wp_get_object_terms