get_attachment_taxonomies( int|array|object $attachment, string $output = ‘names’ ): string[]|WP_Taxonomy[]

In this article

Retrieves taxonomies attached to given the attachment.

Parameters

$attachmentint|array|objectrequired
Attachment ID, data array, or data object.
$outputstringoptional
Output type. 'names' to return an array of taxonomy names, or 'objects' to return an array of taxonomy objects.
Default is 'names'.

Default:'names'

Return

string[]|WP_Taxonomy[] List of taxonomies or taxonomy names. Empty array on failure.

Source

			)
		)
	);

	foreach ( $attachments as $k => $attachment ) {
		if ( (int) $attachment->ID === (int) $post->ID ) {
			break;
		}
	}

	$output        = '';
	$attachment_id = 0;

	if ( $attachments ) {
		$k = $prev ? $k - 1 : $k + 1;

		if ( isset( $attachments[ $k ] ) ) {
			$attachment_id = $attachments[ $k ]->ID;
			$attr          = array( 'alt' => get_the_title( $attachment_id ) );
			$output        = wp_get_attachment_link( $attachment_id, $size, true, false, $text, $attr );
		}
	}

	$adjacent = $prev ? 'previous' : 'next';

	/**
	 * Filters the adjacent image link.
	 *
	 * The dynamic portion of the hook name, `$adjacent`, refers to the type of adjacency,
	 * either 'next', or 'previous'.
	 *
	 * Possible hook names include:
	 *
	 *  - `next_image_link`
	 *  - `previous_image_link`
	 *
	 * @since 3.5.0
	 *
	 * @param string $output        Adjacent image HTML markup.
	 * @param int    $attachment_id Attachment ID
	 * @param string|int[] $size    Requested image size. Can be any registered image size name, or
	 *                              an array of width and height values in pixels (in that order).
	 * @param string $text          Link text.
	 */
	return apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text );
}

/**

Changelog

VersionDescription
4.7.0Introduced the $output parameter.
2.5.0Introduced.

User Contributed Notes

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