wp_get_attachment_metadata
Retrieve attachment meta field for attachment ID.
Description
Parameters (2)
- 0. $post_id — Optional. (int)
- Attachment ID. Default 0.
- 1. $unfiltered — Optional. (bool) =>
false
- If true, filters are not run. Default false.
Usage
if ( !function_exists( 'wp_get_attachment_metadata' ) ) { require_once ABSPATH . WPINC . '/post.php'; } // Attachment ID. Default 0. $post_id = -1; // Optional. If true, filters are not run. Default false. $unfiltered = false; // NOTICE! Understand what this does before running. $result = wp_get_attachment_metadata($post_id, $unfiltered);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/post.php
- function wp_get_attachment_metadata( $post_id = 0, $unfiltered = false ) {
- $post_id = (int) $post_id;
- if ( !$post = get_post( $post_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 $post_id Attachment ID.
- */
- return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID );
- }