Title: Update post term count
Last modified: January 23, 2022

---

# Update post term count

 *  Resolved [Rasso Hilber](https://wordpress.org/support/users/nonverbla/)
 * (@nonverbla)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/update-post-term-count/)
 * Hi there! Love this plugin, great work! One thing I noticed while playing around
   with it: When assigning attachments to terms, the `term_count` for those terms
   doesn’t update. This is due to attachments having the “inherit” post_status, 
   and WordPress only respecting posts with post_status “publish” when counting 
   posts in terms ([more information here](https://developer.wordpress.org/reference/functions/register_taxonomy/)
   at `update_count_callback`). The following snippet solves this for me, maybe 
   you could consider putting it in your plugin?
 *     ```
       /**
        * Adds post_status 'inherit' to the term_count post statuses
        * 
        * @param array $statuses   the statuses (usually contains only 'publish')
        * @param \WP_Taxonomy      the taxonomy WordPress is counting posts for
        */
       add_filter('update_post_term_count_statuses', function($statuses, $taxonomy) {
         if( in_array('attachment', $taxonomy->object_type) ) {
           $statuses[] = 'inherit';
         }
         return $statuses;
       }, 10, 2);
       ```
   
 * I wrote the filter using an anonymous function for brevity, but you should get
   the idea. Hope it’s helpful.

Viewing 1 replies (of 1 total)

 *  Plugin Author [FAKTOR VIER](https://wordpress.org/support/users/faktorvier/)
 * (@faktorvier)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/update-post-term-count/#post-15283286)
 * Hi [@nonverbla](https://wordpress.org/support/users/nonverbla/)
 * Thank you very much for this input and the code snippet!
 * We’ll take a look at that and implement this hook in the next version.

Viewing 1 replies (of 1 total)

The topic ‘Update post term count’ is closed to new replies.

 * ![](https://ps.w.org/f4-media-taxonomies/assets/icon-256x256.jpg?rev=1982635)
 * [F4 Media Taxonomies](https://wordpress.org/plugins/f4-media-taxonomies/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/f4-media-taxonomies/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/f4-media-taxonomies/)
 * [Active Topics](https://wordpress.org/support/plugin/f4-media-taxonomies/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/f4-media-taxonomies/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/f4-media-taxonomies/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [FAKTOR VIER](https://wordpress.org/support/users/faktorvier/)
 * Last activity: [4 years, 4 months ago](https://wordpress.org/support/topic/update-post-term-count/#post-15283286)
 * Status: resolved