WP_Term_Query Generator

Home » WordPress Generators » WP_Term_Query Generator

Related query generators WP user query generator WP query generator WP comment query generator Go back to all generators

The query variable to use for this snippet.
Add The Loop
Whether to add the display loop code to the snippet.
Taxonomy or a comma-seperated list of taxonomies to be filtered in this query.
Term or a comma-seperated list of terms to be filtered in this query.
Term slug or a comma-seperated list of term slugs to be filtered in this query.
Return terms that are included in this comma-seperated list of term IDs.
Return terms that are excluded in this comma-seperated list of term IDs.
Return terms and their descendants that are excluded in this comma-seperated list of term IDs.
Return child terms of this term ID. WordPress ignores this when multiple taxonomies are passed.
Return child terms of this parent term ID.
Hierarchical
Whether to include terms that have non-empty descendants (even if $hide_empty is set to true).
Only Childless Terms
Whether to include terms that have no children (even if $hide_empty is set to true).
The number of items that should be returned per page.
The number of items to offset the query. This is basically the page number attribute.
The field to order the terms by.
The order to return the terms in.
The meta key to query against.
The meta value to query against.
The fields to return in the results. Defaults to all fields.
Hide Empty
Hides terms that are empty (aren’t assigned to any posts.).
Whether to return terms regardless of ancestry or whether the terms are empty. Accepts ‘all’ or empty (disabled). Default empty.
Count Only
Whether to return a count of all the terms or the terms themselves.
Pad Counts
Whether to pad the quantity of a term’s children in the quantity of each term’s “count” object variable. Default false.
Cache
Whether to cache the results of the query.
The key to use to cache the results of the query.
                    $query_args = array(
	'hierarchical' => true,
	'childless' => false,
	'number' => 10,
	'order' => 'ASC',
	'orderby' => 'name',
	'fields' => 'all',
	'hide_empty' => true,
	'get' => 'empty',
	'count' => false,
	'pad_counts' => false,
	'update_term_meta_cache' => false,
);

$query = new WP_Query( $query_args );

if ( ! empty( $query ) && ! is_wp_error( $query ) ) {
	// The Loop
}
else {
	// no terms found
}
                

Sign up to save your WordPress snippets on WPTurbo.