Make WordPress Core

Opened 14 years ago

Closed 5 years ago

Last modified 5 years ago

#15806 closed defect (bug) (worksforme)

get_terms with hide_empty returns count > 0 with unpublished items

Reported by: bendog's profile bendog Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Taxonomy Keywords: reporter-feedback needs-unit-tests bulk-reopened
Focuses: Cc:



I think that's a bug.

I've defined a custom post type and a custom category taxonomy for it.

On my front end, i'm using get_terms with hide_empty to show the categories of the existing custom post type.

get_terms does ignore unpublished posts but it seems to include trashed item.

I have one category that is linked to only a trashed item and the function includes it in the count.

I can't select 3.0.3 in the version dropdown but it happened on any 3.0.x that I tried.

Attachments (1)

15806.diff (2.3 KB) - added by boonebgorges 8 years ago.

Download all attachments as: .zip

Change History (15)

#1 @scribu
14 years ago

  • Cc scribu added

#2 @neoxx
13 years ago

  • Cc neo@… added
  • Keywords changed from taxonomy, custom post to taxonomy custom post

In 3.2 I could also reproduce the bug with an unpublished post in combination with an otherwise not assigned custom taxonomy term. (get_terms w/ hide_empty)

#3 @vtowel
13 years ago

  • Summary changed from get_terms with hide_empty returns count > 0 with trashed items to get_terms with hide_empty returns count > 0 with unpublished items

I could also reproduce this bug with posts pending approval. Their tags/categories shouldn't show up in the front end if those tags/categories are otherwise unused by published posts. Even better would be for get_terms to have an option specifying desired post status, "publish" being the default value.

#4 @SergeyBiryukov
13 years ago

  • Keywords needs-patch added; taxonomy custom post removed

#5 @jtwg
13 years ago

Just ran into this same problem. Custom post type with custom taxonomy, custom taxonomy returning results with posts in trash.

#6 @jgadbois
13 years ago

  • Cc jgadbois added

Seems like either a join will be needed in get_terms() or wp_update_term_count_now() will need to be modified to only count terms tied to published posts. This second method will also require counts to be updated when post status changes.

I'd be happy to look at this one...anyone want to chime in as to which approach would be preferred?

#7 @paudelvinay
12 years ago

  • Cc paudelvinay added
  • Severity changed from minor to major
  • Version changed from 3.0.2 to 3.2.1

Is there any progress on get_terms with unpublished post/private posts for custom taxonomy?

#8 @SergeyBiryukov
12 years ago

  • Version changed from 3.2.1 to 3.0

Version number indicates when the bug was initially introduced/reported.

#9 @barrykooij
11 years ago

  • Cc wpcore@… added
  • Resolution set to worksforme
  • Status changed from new to closed

I tried to reproduce this bug in version 3.6-alpha-23791 and it appears to be working correctly now.

Last edited 11 years ago by barrykooij (previous) (diff)

#10 @markoheijnen
11 years ago

  • Keywords needs-patch removed
  • Milestone Awaiting Review deleted

#11 @fetard
8 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened
  • Version 3.0 deleted

The problem is still present in 4.5.3 (with custom taxonomy and custom post type)

#12 @ocean90
8 years ago

  • Keywords reporter-feedback needs-unit-tests added
  • Milestone set to Awaiting Review
  • Severity changed from major to normal
  • Version set to 3.0

@fetard Hi, can you provide the code you're using and/or steps to reproduce this issue?

8 years ago

#13 @boonebgorges
8 years ago

I can't reproduce the issue .15806.diff includes tests for a number of situations, all of which seem to work as expected: 'draft' posts are excluded, posts that transition from 'publish' to 'draft' are excluded, posts that transition from 'publish' to 'trash' are excluded.

In his comment above, @ocean90 asked for details to reproduce. Specifically, it would be helpful to see the code used to register the post type and taxonomy. If the post type is providing its own update_count_callback, then it needs to be responsible for its own resetting of term counts.

#16 @boonebgorges
5 years ago

  • Keywords bulk-reopened added
  • Resolution set to worksforme
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.