Make WordPress Core

Opened 11 years ago

Last modified 3 years ago

#22558 new defect (bug)

Attachment term counts feels/are inaccurate

Reported by: ocean90's profile ocean90 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Media Keywords: 2nd-opinion needs-testing
Focuses: administration 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 (12)

#1 follow-up: @nacin
11 years ago

Does not sound like a regression, can someone confirm?

#2 in reply to: ↑ 1 @ocean90
11 years 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.

#3 @havahula
11 years 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.

#4 @SergeyBiryukov
11 years ago

#23530 was marked as a duplicate.

#5 @ocean90
11 years ago

  • Description modified (diff)

#6 @TomAuger
11 years 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.

#7 @SergeyBiryukov
10 years ago

#29703 was marked as a duplicate.

#8 @chriscct7
8 years ago

  • Keywords needs-testing added

#9 @ocean90
7 years ago

#41814 was marked as a duplicate.

#10 @SergeyBiryukov
4 years ago

#48454 was marked as a duplicate.

#11 @mightyturtle
4 years ago

  • Focuses administration added

Bump. I'm kind of amazed that this bug has been outstanding for so long...

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


3 years ago

Note: See TracTickets for help on using tickets.