Get All Terms of a Taxonomy and Their Post Count

Home » Snippets » Get All Terms of a Taxonomy and Their Post Count
0

Created with:

WP_Term_Query Generator

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
				$query_args = [
	'taxonomy' => [
		'recipes',
	],
	'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_Term_Query( $query_args );

if ( ! empty( $query ) && ! is_wp_error( $query ) ) {
	foreach ( $query as $term ) {
		// do something
	}
}
else {
	// no terms found
}
			

Register an account to save your snippets or go Pro to get more features.