WordPress at a glance

wp_get_attachment_metadata() WP 1.0

Retrieve attachment meta field for attachment ID.

Works based on: get_post_meta()
1 time — 0.000745 sec (slow) | 50000 times — 1.22 sec (fast) | PHP 7.0.8, WP 4.6
Hooks from the function
Return

Array|false. Attachment metadata. False on failure.

Usage

wp_get_attachment_metadata( $attachment_id, $unfiltered );
$attachment_id(int)
Attachment post ID.
Default: global $post
$unfiltered(true|false)
If true, filters are not run.
Default: false

Changelog

Since 2.1.0 Introduced.

Code of wp_get_attachment_metadata() WP 5.7.2

<?php
function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
	$attachment_id = (int) $attachment_id;

	if ( ! $attachment_id ) {
		$post = get_post();

		if ( ! $post ) {
			return false;
		}

		$attachment_id = $post->ID;
	}

	$data = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );

	if ( ! $data ) {
		return false;
	}

	if ( $unfiltered ) {
		return $data;
	}

	/**
	 * Filters the attachment meta data.
	 *
	 * @since 2.1.0
	 *
	 * @param array $data          Array of meta data for the given attachment.
	 * @param int   $attachment_id Attachment post ID.
	 */
	return apply_filters( 'wp_get_attachment_metadata', $data, $attachment_id );
}

From category: Metadata (postmeta)

No comments
    Log In