• Resolved Rasso Hilber

    (@nonverbla)


    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 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)
Viewing 1 replies (of 1 total)
  • The topic ‘Update post term count’ is closed to new replies.