Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#33622 closed defect (bug) (invalid)

Category counter is not working for attachment post type

Reported by: johnoak's profile JohnOak Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4
Component: Taxonomy Keywords:
Focuses: ui, administration Cc:

Description

When registering a custom taxonomy for "attachment" post type:

register_taxonomy( 'test', 'attachment', [
	"label" => "Test",
	"singular_label" => "Test",
]);

And setting taxonomy value for attachment file:

http://engineer.lv/wp-bug.png

The count for items in registered taxonomy shows 0 (if there is 1 or more items it will still show 0 an this is the problem):

http://engineer.lv/wp-bug-2.png

When clicking on count (that shows 0) opens Media Library with items that have this taxonomy value. And in here everything is just fine:

http://engineer.lv/wp-bug-3.png

The problem is that wrong counter that should be fixed.

Bug was tested with clean WordPress install with no plugins and on clean Twenty Fifteen child theme.

Change History (3)

#1 @swissspidy
9 years ago

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

Please have a look at the documentation of the update_count_callback parameter in the WordPress Codex: https://codex.wordpress.org/Function_Reference/register_taxonomy. This is by design.

Because an attachment is a type of post, the default _update_post_term_count() will be used. However, this may be undesirable, because this will only count attachments that are actually attached to another post (like when you insert an image into a post). This means that attachments that you simply upload to WordPress using the Media Library, but do not actually attach to another post will not be counted.

#2 @ocean90
7 years ago

#40896 was marked as a duplicate.

#3 @ocean90
7 years ago

Related: #22558

Note: See TracTickets for help on using tickets.