WordPress at a glance

wp_get_attachment_metadata() WP 1.0

Retrieve attachment meta field for attachment ID.

✈ 1 time = 0.000745s = slow | 50000 times = 1.22s = fast PHP 7.0.8, WP 4.6
Hooks from function:
Return

Mixed. Attachment meta field. 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

Code of wp_get_attachment_metadata: wp-includes/post.php VER 4.9.8

<?php
function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
	$attachment_id = (int) $attachment_id;
	if ( ! $post = get_post( $attachment_id ) ) {
		return false;
	}

	$data = get_post_meta( $post->ID, '_wp_attachment_metadata', true );

	if ( $unfiltered )
		return $data;

	/**
	 * Filters the attachment meta data.
	 *
	 * @since 2.1.0
	 *
	 * @param array|bool $data          Array of meta data for the given attachment, or false
	 *                                  if the object does not exist.
	 * @param int        $attachment_id Attachment post ID.
	 */
	return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID );
}

Related Functions

From category: Metadata (postmeta)

No comments
    Hello, !     Log In . Register