get_taxonomies_for_attachments( string $output = ‘names’ ): string[]|WP_Taxonomy[]

Retrieves all of the taxonomies that are registered for attachments.

Description

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

See also

Parameters

$outputstringoptional
The type of taxonomy output to return. Accepts 'names' or 'objects'.
Default 'names'.

Default:'names'

Return

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

Source


/**
 * Retrieves taxonomies attached to given the attachment.
 *
 * @since 2.5.0
 * @since 4.7.0 Introduced the `$output` parameter.
 *
 * @param int|array|object $attachment Attachment ID, data array, or data object.
 * @param string           $output     Output type. 'names' to return an array of taxonomy names,
 *                                     or 'objects' to return an array of taxonomy objects.
 *                                     Default is 'names'.
 * @return string[]|WP_Taxonomy[] List of taxonomies or taxonomy names. Empty array on failure.
 */
function get_attachment_taxonomies( $attachment, $output = 'names' ) {
	if ( is_int( $attachment ) ) {
		$attachment = get_post( $attachment );
	} elseif ( is_array( $attachment ) ) {
		$attachment = (object) $attachment;

Changelog

VersionDescription
3.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.