Constructor.
Sets up the term query, based on the query vars passed.
$querystring|arrayoptional
taxonomy string|string[]object_ids int|int[]orderby string'name', 'slug', 'term_group', 'term_id', 'id', 'description', 'parent', 'term_order'). Unless $object_ids is not empty, 'term_order' is treated the same as 'term_id'.'count' to use the number of objects associated with the term.'include' to match the 'order' of the $include param.'slug__in' to match the 'order' of the $slug param.'meta_value''meta_value_num'.$meta_key.$meta_query.'none' to omit the ORDER BY clause.'name'.order string'ASC' (ascending) or 'DESC' (descending).'ASC'.hide_empty bool|int1|true or 0|false. Default 1|true.include int[]|stringexclude int[]|string$include is non-empty, $exclude is ignored.exclude_tree int[]|string$include is non-empty, $exclude_tree is ignored. Default empty array.number int|string''|0 (all) or any positive number. Default ''|0 (all). Note that $number may not return accurate results when coupled with $object_ids.offset intfields string'all' Returns an array of complete term objects (WP_Term[]).'all_with_object_id' Returns an array of term objects with the 'object_id' param (WP_Term[]). Works only when the $object_ids parameter is populated.'ids' Returns an array of term IDs (int[]).'tt_ids' Returns an array of term taxonomy IDs (int[]).'names' Returns an array of term names (string[]).'slugs' Returns an array of term slugs (string[]).'count' Returns the number of matching terms (int).'id=>parent' Returns an associative array of parent term IDs, keyed by term ID (int[]).'id=>name' Returns an associative array of term names, keyed by term ID (string[]).'id=>slug' Returns an associative array of term slugs, keyed by term ID (string[]).'all'.name string|string[]slug string|string[]term_taxonomy_id int|int[]hierarchical bool$hide_empty is set to true). Default true.search stringname__like string$name__like. description__like string$description__like. pad_counts boolget string'all' or '' (disabled). Default ''.child_of int$child_of is ignored. Default 0.parent intchildless boolcache_domain string'core'.cache_results boolupdate_term_meta_cache boolmeta_key string|string[]meta_value string|string[]meta_compare stringmeta_compare_key stringmeta_type stringmeta_type_key stringmeta_query arrayDefault:''
public function __construct( $query = '' ) {
$this->query_var_defaults = array(
'taxonomy' => null,
'object_ids' => null,
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => true,
'include' => array(),
'exclude' => array(),
'exclude_tree' => array(),
'number' => '',
'offset' => '',
'fields' => 'all',
'name' => '',
'slug' => '',
'term_taxonomy_id' => '',
'hierarchical' => true,
'search' => '',
'name__like' => '',
'description__like' => '',
'pad_counts' => false,
'get' => '',
'child_of' => 0,
'parent' => '',
'childless' => false,
'cache_domain' => 'core',
'cache_results' => true,
'update_term_meta_cache' => true,
'meta_query' => '',
'meta_key' => '',
'meta_value' => '',
'meta_type' => '',
'meta_compare' => '',
);
if ( ! empty( $query ) ) {
$this->query( $query );
}
}
| Version | Description |
|---|---|
| 6.4.0 | Introduced the 'cache_results' parameter. |
| 5.3.0 | Introduced the 'meta_type_key' parameter. |
| 5.1.0 | Introduced the 'meta_compare_key' parameter. |
| 4.9.0 | Added 'slug__in' support for 'orderby'. |
| 4.7.0 | Introduced 'object_ids' parameter. |
| 4.6.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_term_query/__construct