The get_terms_defaults WordPress PHP filter allows you to modify the default arguments for the get_terms()
function.
Usage
add_filter('get_terms_defaults', 'customize_get_terms_defaults', 10, 2); function customize_get_terms_defaults($defaults, $taxonomies) { // Your custom code here return $defaults; }
Parameters
$defaults
(array) – An array of defaultget_terms()
arguments.$taxonomies
(string[]) – An array of taxonomy names.
More information
See WordPress Developer Resources: get_terms_defaults
Examples
Change the default order
Customize the default order of terms to be ordered by their description.
add_filter('get_terms_defaults', 'order_by_description', 10, 2); function order_by_description($defaults, $taxonomies) { $defaults['orderby'] = 'description'; return $defaults; }
Set default number of terms to retrieve
Set the default number of terms to 15.
add_filter('get_terms_defaults', 'set_default_terms_number', 10, 2); function set_default_terms_number($defaults, $taxonomies) { $defaults['number'] = 15; return $defaults; }
Show only empty terms by default
Display only terms with no posts assigned by default.
add_filter('get_terms_defaults', 'show_empty_terms', 10, 2); function show_empty_terms($defaults, $taxonomies) { $defaults['hide_empty'] = false; return $defaults; }
Exclude a specific term by default
Exclude a specific term by its ID from the terms list by default.
add_filter('get_terms_defaults', 'exclude_specific_term', 10, 2); function exclude_specific_term($defaults, $taxonomies) { $defaults['exclude'] = array(42); // Exclude term with ID 42 return $defaults; }
Set default fields to return
Change the default fields to return only term IDs.
add_filter('get_terms_defaults', 'set_default_fields', 10, 2); function set_default_fields($defaults, $taxonomies) { $defaults['fields'] = 'ids'; return $defaults; }