Make WordPress Core

Opened 5 years ago

Last modified 16 months ago

#35995 new defect (bug)

Registering taxonomies for attachment mime types

Reported by: mboynes Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.5
Component: Taxonomy Keywords: needs-patch
Focuses: Cc:


I stumbled across an interesting unit test in core that led me down a bit of a rabbit hole.

The test test_tax_query_taxonomy_with_attachments() in phpunit/tests/query/taxQuery.php calls:

register_taxonomy_for_object_type( 'post_tag', 'attachment:image' );

I never knew that you could register a taxonomy to a mime type, so I looked into it, but from what I've found the support seems spotty.

First off, calling register_taxonomy_for_object_type( 'post_tag', 'attachment:image' ); fails and returns false. As best I can tell, this is because get_post_type_object( 'attachment:image' ) fails, since $wp_post_types['attachment:image'] is not set. For the purposes of testing the query support, I added a taxonomy to an attachment mime type "the hard way" using the following:

$GLOBALS['wp_taxonomies']['post_tag']->object_type[] = 'attachment:image';

On the querying side of the equation, support seems much better. The only area that's iffy is if you register a taxonomy to the 'attachment' post type, but pass the mime type (e.g. 'attachment:image') to get_object_taxonomies(), you won't get the registered taxonomy. Since attachment:image is a subset of attachment, I would expect to get all the "attachment" taxonomies as well.

Breaking this all down, the main bug here is that it doesn't seem to be possible to register a taxonomy to an attachment mime type, despite there being support for this feature otherwise.

Side note, since the unit test test_tax_query_taxonomy_with_attachments() fails in registering a taxonomy to an attachment mime type, the rest of this unit test probably should have failed (for a couple of reasons).

Change History (2)

#1 @obenland
4 years ago

  • Version trunk deleted

#2 @boonebgorges
4 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release
  • Version set to 3.5

Looks like support for attachment:image and friends was introduced in [21948]. That's a good place to start to determine the extent to which we want to support the full gamut of the taxonomy API for these types of taxonomies.

Note: See TracTickets for help on using tickets.