2

wp_count_terms() counts the number of terms in a taxonomy but not the number of post that have those terms and I've found that wp_count_post() does not accept a taxonomy.

So whats a guy gotta do to count the number of post in a taxonomy term?

Example:

Term: Apples Post: 89 (this is what I want to get, the number of post with the 'Apples' taxonomy)

Thanks!

1 Answer 1

9

The function you are looking for is get_term() http://codex.wordpress.org/Function_Reference/get_term

and the code would look something like this:

$term = get_term( 1, 'category' );//for example uncategorized category
echo 'count: '. $term->count;
3
  • 1
    Does this count deleted posts as well ?
    – divyenduz
    Commented Sep 22, 2016 at 8:30
  • will count only published posts, which might or might not be enough Commented Sep 28, 2017 at 20:30
  • @jon-furry -- $term->count can be calculated to include other posts that appear in the All view of the admin table if you use the hook found in this answer.
    – Mort 1305
    Commented Mar 30, 2022 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.