WordPress.org

Make WordPress Core

Opened 17 months ago

Last modified 11 months ago

#22558 new defect (bug)

Attachment term counts feels/are inaccurate

Reported by: ocean90 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Media Keywords: 2nd-opinion
Focuses: Cc:

Description (last modified by ocean90)

For posts:

  • Assign a term to a post, save as draft. Term count returns 0.
  • Publish the post. Term count returns 1.
  • Change post status back to draft. Term count returns 0.

For attachments:

  • Upload an image, assign a term. Term count returns 0.
  • Create a new post and insert the image in a published post. Term count returns 0.
  • Create a new post, use the insert media modal and upload an image. Then go the the media edit screen and assign a term to the image. Term count returns 1.
  • Change the post status back to draft. Term count returns 1.
  • Upload an image, assign a term, attach the attachment to a published post. Term count returns 0.

The default term update callback is _update_post_term_count. The function includes a special case for attachments, that's the reason why we have the 1 in step 3.

IMO the term count for attachments shouldn't rely on the parent post status. We should just force _update_generic_term_count.

Also noted here: comment:ticket:21391:41

Change History (6)

comment:1 follow-up: nacin17 months ago

Does not sound like a regression, can someone confirm?

comment:2 in reply to: ↑ 1 ocean9017 months ago

Replying to nacin:

Does not sound like a regression, can someone confirm?

No, not a regression. But more prominent now, since the UI is there.

comment:3 havahula15 months ago

I can confirm that all those steps are accurate.

By way of a use-case scenario:
If you're using the new Attachment Post UI, to create an asset management tool with a custom taxonomy as the organizing mechanism, all attachments without post parents (unattached) will be correctly added to the selected terms. however, if you run a query using get_categories() you must set 'hide_empty' to false in order to show the attachments, which of course, means they're not registering in the 'count' column in term_taxonomy.

comment:4 SergeyBiryukov14 months ago

#23530 was marked as a duplicate.

comment:5 ocean9014 months ago

  • Description modified (diff)

comment:6 TomAuger11 months ago

+1 to force _update_generic_term_count, unless there's a really compelling reason that we want to favour attachments actually attached to posts.

Easy fix though when registering the taxonomy. Will update Codex in the meantime.

Note: See TracTickets for help on using tickets.