WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 14 months ago

#14084 closed defect (bug)

Custom taxonomy count includes draft & trashed posts — at Version 8

Reported by: lumpysimon Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Taxonomy Keywords: has-patch 3.2-early dev-feedback needs-refresh
Focuses: Cc:

Description (last modified by dd32)

I have registered a custom post type and an associated non-hierarchical custom taxonomy.

The tag count, both on edit-tags.php?taxonomy=my_tag&post_type=my_post and when using wp_tag_cloud, includes draft & trashed posts in the count.

The count should only include published posts.

This error doesn't seem to occur for normal posts/tags, only for custom posts types/taxonomies.

--
Added by dd32: The count on the taxonomy page is currently global, It includes All post types regardless of the post status (ie. published vs trashed, published vs custom_status)

Change History (8)

comment:1 scribu4 years ago

Related: #14076

comment:2 bunnykins4 years ago

I am a bit confused here how is this bug related to mine?
According to my bug report the count displayed next the the category is correct as I do have that many entries in that category. However those entries are in a different post type so when you click on that category it acts as if there is no entries at all in that category.
I did how ever find a work around and that is to create the entry in both the regular post type and in the new post type and make sure both entries have the same permlink and you should be able to see those entries when you click on that category or tag.

comment:3 kevinB4 years ago

  • Cc kevinB added

comment:4 lumpysimon4 years ago

  • Cc piemanek@… added

I've just noticed that this bug also affects the count for hierarchical taxonomies associated with custom post types, for instance when you use wp_list_categories( 'taxonomy=my_taxo&show_count=1' ).

comment:5 nacin3 years ago

  • Milestone changed from Awaiting Review to Future Release

comment:6 mfields3 years ago

  • Cc michael@… added

comment:7 mfields3 years ago

I have witnessed the behavior that lumpysimon has reported.

If the 'update_count_callback' argument is not defined when a custom taxonomy is registered it's value is set to empty and the post count will not be updated when post_status is changed, only when published. However, if a custom taxonomy's 'update_count_callback' argument is set to '_update_post_term_count', the count will be updated when post_status is changed from a value of 'publish', 'draft' or 'pending' to a value of 'publish', 'draft' or 'pending'.

I'm not sure whether or not it is a good idea to suggest that users set the value of 'update_count_callback' to a function marked as private in core. Would it be better to have register_taxonomy() set this function for the user instead of giving it an empty value?

In my tests I never witnessed the count being updated when a post's status was changed to or from 'trash'. I believe this to be a bug.

comment:8 dd323 years ago

  • Description modified (diff)

I've closed #14076 as a duplicate of this ticket.

The count on the taxonomy page is currently global, It includes All post types regardless of the post status (ie. published vs trashed, published vs custom_status)

Last edited 15 months ago by SergeyBiryukov (previous) (diff)
Note: See TracTickets for help on using tickets.