WordPress.org

Make WordPress Core

Opened 10 years ago

Closed 6 years ago

#11847 closed defect (bug) (fixed)

wp_tag_cloud counts terms attached to future posts when used with custom taxonomies

Reported by: fwiffo Owned by: filosofo
Milestone: Priority: normal
Severity: normal Version: 2.9.1
Component: Taxonomy Keywords:
Focuses: Cc:
PR Number:

Description

If you create a custom taxonomy, then attach some terms from that taxonomy to a future scheduled post, attachments attached to a future post, or unattached attachments, they will get counted toward the totals used to draw the tag cloud produced by wp_tag_cloud.

As a result, the sizes of the items in the tag cloud will be wrong, and the tooltips will show the wrong count. In some cases, if a particular term is only attached to future posts, clicking on the link in the tag cloud will result in a 404 because the main $wp_query correctly filters out future posts and unattached attachments when looking at the term's archive.

Correct behavior would be for get_terms to provide an option to filter out future posts and unattached attachments from its results the same as is done when looking at the term's archive.

Attachments (1)

fix-counts.php (2.0 KB) - added by fwiffo 10 years ago.
workaround filter on get_terms

Download all attachments as: .zip

Change History (8)

#1 @nacin
10 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

Closing this a duplicate of #10142. See also this comment in #9674.

#2 @nacin
10 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

Reading the ticket again, I was definitely too quick to mark this as a limitation of taxonomies, versus an actual bug.

#3 @dd32
10 years ago

  • Milestone changed from Unassigned to Future Release

The problem with this is, That the count is only of the terms usage, So if a term is used on an attachment, draft post, page, or published post, it'll increment that counter.

unfortunately, that leads to the problem whereby, the term is used, but not on a visible object.

On the term archive, Its a different story, That ignores the count field, it queries wp_posts directly for all the posts that match (criteria, published post, etc) and exist within the (term of taxonomy) relationship table.

@fwiffo
10 years ago

workaround filter on get_terms

#4 @fwiffo
10 years ago

I actually implemented a workaround by adding a filter on get_terms in my plugin (eidogo-for-wordpress). When I call wp_tag_cloud I add a parameter which the filter looks for. It then does a count for the terms restricting post counts the same way the term archive does.

I've attached the relevant filter function in case it's useful to anyone else running into this.

#5 @kevinB
9 years ago

  • Cc kevinB added

#6 @mfields
9 years ago

  • Cc michael@… added

#7 @wonderboymusic
6 years ago

  • Milestone Future Release deleted
  • Resolution set to fixed
  • Status changed from reopened to closed

_pad_term_counts() checks post_status = 'publish' now (4 years later)

Note: See TracTickets for help on using tickets.