I have a little problem with category post counting. Basically, I made a custom post type, say ‘movie’, using "custom type post UI" plugin, and linked it with built-in category. Also, I am using the option ‘show posts count’ in category widget. So far so good. Now, is there a way to count the number of posts except custom ones? For example, one of my category, say ‘hobby’, has 5 normal posts + 3 custom ‘movie’ posts. Then, I want to have something like ‘hobby (5)’, not ‘hobby (8)’. In short, I wanted to know how to counts the number of posts that does not have a post type 'movie'. If it is possible, I just want to add a function in functions.php to resolve this problem.

Thank you in advance.

p.s. – For actual example, you may want to check the following link: http://www.mathstorehouse.com/archives/category/mathematics/discrete-math/graph-theory In the graph-theory category, there are one normal post and one custom post. So, if I click the link, it shows a normal post only (which is what I intended). However, if you look at a category widget, it says I have two posts in the graph-theory category.

1 Answer 1


When registering a custom taxonomy, register_taxonomy() accepts an update_count_callback argument.

This callback function will be called when the count is updated. The default callback is _update_post_term_count() for taxonomies attached to post types, which confirms that the objects are published before counting them.

_update_generic_term_count() is the default for taxonomies attached to other object types, such as users.

You can check out the code for both functions to see how you can create your own callback to make the count more accurate.

  • Thanks for the answer. but sorry, I didn't get it. I didn't register a custom taxonomy, but I registered a custom post type and use a built-in category to categorize custom posts. So, each category can contain both normal posts and 'custom' posts. However, I want my category to count normal posts only.
    – jjycjn
    Feb 9, 2018 at 15:35

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.