Custom Taxonomy Post Count Incorrect
-
In a nutshell, my issue is that my custom taxonomy term post count is including published, draft and trashed posts.
I did a little searching on this topic around the internets and it seemed like other people may have been having the same problem that I am having, but I was unable to find a resolution to it.
I have a custom post type which has it’s own custom taxonomy. I list these custom taxonomy terms in a
<ul>
that includes the term name and the count of posts in that term. It all seems to work great, until you delete/draft one of these custom posts. The number of posts in the term does not go down. It counts all post, trashed/drafted/pending review.<?php //List terms in a given taxonomy $taxonomy = 'industry'; $term_args=array( 'hide_empty' => false, 'orderby' => 'name', 'order' => 'ASC' ); $tax_terms = get_terms($taxonomy,$term_args); ?> <ul> <?php foreach ($tax_terms as $tax_term) { echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all vendors in the %s industry" ), $tax_term->name ) . '" ' . '>' . $tax_term->name . '<span class="count">' . $tax_term->count . '</span></a></li>'; } ?> </ul>
Anyone have any ideas on how to fix this?
- The topic ‘Custom Taxonomy Post Count Incorrect’ is closed to new replies.