GeneratorsQueryTerm Query Builder

Term Query Builder

Fetch terms with hide_empty, ordering and meta clauses — with the parent/child_of mixup and the pad_counts fix called out before your menu loses a level.

category-query.php
Saved just now
Which terms
No hierarchy filter — every term at every depth, flat.
Order and shape
hide_empty
Skip terms with nothing attached.
pad_counts
Roll child counts up into the parent.
Match the slug exactly
Use the slug argument instead of a fuzzy name search.
exclude_tree
Exclude the listed terms and everything beneath them.
Prime the term meta cache
One query for all term meta instead of one per term.
Term meta
none
No term meta clauses.
The class with get_terms(), plus a list that links each term.
// Generated with WP CodeKit — powered by GrowQuest (https://growquest.io).
$query = new WP_Term_Query( array(
	'taxonomy'   => 'category',
	'hide_empty' => true,
	'exclude'    => array( 1 ),
	'orderby'    => 'count',
	'order'      => 'DESC',
	'number'     => 10,
	'pad_counts' => true,
) );

$terms = $query->get_terms();

if ( $terms ) {
	echo '<ul>';

	foreach ( $terms as $term ) {
		printf(
			'<li><a href="%1$s">%2$s</a> <span>%3$s</span></li>',
			esc_url( get_term_link( $term ) ),
			esc_html( $term->name ),
			esc_html( number_format_i18n( $term->count ) )
		);
	}

	echo '</ul>';
}