Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 4 years ago

#29745 closed defect (bug) (duplicate)

Post count incorrect for shared custom taxonomy in context of post type

Reported by: jchristopher's profile jchristopher Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.1
Component: Taxonomy Keywords: has-patch
Focuses: administration Cc:

Description (last modified by SergeyBiryukov)

I found other tickets that may tackle a variation of this issue, but they seem to focus on post_status as opposed to post_type — hoping this isn't a dupe of the following:

#24305 #18072 #14073 #13670

I have a custom taxonomy (collection) that I'm sharing among two custom post types (product and lookbook). Products are part of a Collection, and each Collection has a Lookbook, so each 'lookbook' shares a 'collection' term with a 'product'.

I believe there's a bug concerning the Count when viewing the Collections term list when in context of Products vs. Lookbooks.

For example, I have created a single product with a collection term of 'Fall':

When viewing Collections under the Products CPT menu, the Count column is accurate:

However (even though I haven't added any Lookbooks yet) when I view Collections under the Lookbooks CPT menu I assume that these counts will represent the counts of that CPT ('lookbook'), but it appears to simply retrieve the count stored in the database, which is an overall count of term usage, not limited to any particular post type:

Clicking the count brings you to a CPT listing page filtered down to the Fall collection term as expected, with no posts (expected), but the original count of 1 is incorrect:

I've included a patch but would love to hear what you think about a better approach to this. I considered whether adjusting get_terms() to accept a post_type parameter was acceptable but it didn't seem like an appropriate place to make an adjustment like this.

Attachments (2)

29745.patch (1.4 KB) - added by jchristopher 10 years ago.
Correct taxonomy term Count when filtering by post type
29745-2.patch (1.4 KB) - added by jchristopher 10 years ago.

Download all attachments as: .zip

Change History (8)

10 years ago

Correct taxonomy term Count when filtering by post type

#1 @jchristopher
10 years ago

It occurs to me that with an abundance of posts this won't be ideal performance-wise. Any suggested improvements are much appreciated.

Update: updated patch to utilize WP_Query's found_posts to help with a large volume of posts.

Last edited 10 years ago by jchristopher (previous) (diff)

#2 @jchristopher
10 years ago

  • Keywords has-patch added

#3 @SergeyBiryukov
10 years ago

  • Description modified (diff)

#4 follow-up: @SergeyBiryukov
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #14076, #14084, #20708, #24376, #25188, #28629, #29016.

#5 in reply to: ↑ 4 @jchristopher
10 years ago

Replying to SergeyBiryukov:

Duplicate of #14076, #14084, #20708, #24376, #25188, #28629, #29016.

Oh man, thank you! I know you pretty much have Trac memorized, but I wish I found a couple of these before posting.

Note: See TracTickets for help on using tickets.