get_taxonomies_for_attachments() WordPress Function

The get_taxonomies_for_attachments() function is used to get the taxonomies for attachments. This function is useful for getting the taxonomies for attachments that are associated with a post.

get_taxonomies_for_attachments( string $output = 'names' ) #

Retrieves all of the taxonomies that are registered for attachments.


Description

Handles mime-type-specific taxonomies such as attachment:image and attachment:video.

Top ↑

See also


Top ↑

Parameters

$output

(string)(Optional) The type of taxonomy output to return. Accepts 'names' or 'objects'.

Default value: 'names'


Top ↑

Return

(string[]|WP_Taxonomy[]) Array of names or objects of registered taxonomies for attachments.


Top ↑

Source

File: wp-includes/media.php

function get_taxonomies_for_attachments( $output = 'names' ) {
	$taxonomies = array();

	foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) {
		foreach ( $taxonomy->object_type as $object_type ) {
			if ( 'attachment' === $object_type || 0 === strpos( $object_type, 'attachment:' ) ) {
				if ( 'names' === $output ) {
					$taxonomies[] = $taxonomy->name;
				} else {
					$taxonomies[ $taxonomy->name ] = $taxonomy;
				}
				break;
			}
		}
	}

	return $taxonomies;
}


Top ↑

Changelog

Changelog
VersionDescription
3.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More