I want to show on a list of taxonomy with corresponding posts counts of published items only. Checking the WP documentation, It seems I can ALMOST achieve that by using the get_terms function https://developer.wordpress.org/reference/functions/get_terms/ but I get ALL the posts counts including draft and trashed.
$taxonomy = 'item_category';
$args = array(
'hide_empty' => false,
'orderby' => 'name',
'order' => 'ASC'
);
$terms = get_terms( $taxonomy , $args );
foreach( $terms as $term ) {
echo $term->name . ' - ' . $term->count . '<br/>';
}
Does WP have a built in args to display it from the get_terms function because I don't see it under the documentation? Is there any other functions or filter that I can try to achieve my desired output?
_update_post_term_count()
.