wp_get_attachment_metadata()获取附件的元数据信息

目录

描述

译文

检索附件meta的附件编号。

原文

Retrieve attachment meta field for attachment ID.

wp_get_attachment_metadata() 描述

用法

<?php wp_get_attachment_metadata$attachment_id$unfiltered ); ?>

wp_get_attachment_metadata() 用法

参数

$attachment_id

(integer) (必填) Attachment ID

默认值: None

$unfiltered

(boolean) (可选) If true, filters are not run.

默认值: false

wp_get_attachment_metadata() 参数

返回值

(array|boolean

Attachment meta field. False on failure.

The fields are:

width 

(integer) The width of the attachment

height 

(integer) The height of the attachment

file 

(string) The file path relative to `wp-content/uploads/`

sizes 

(array) Keys are size slugs, each value is an array containing 'file', 'width', 'height', and 'mime-type'

image_meta 

(array)

wp_get_attachment_metadata() 返回值

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
   Array
   (
       [width] => 2400
       [height] => 1559
       [file] => 2011/12/press_image.jpg
       [sizes] => Array
           (
               [thumbnail] => Array
                   (
                       [file] => press_image-150x150.jpg
                       [width] => 150
                       [height] => 150
                       [mime-type] => image/jpeg
                   )
               [medium] => Array
                   (
                       [file] => press_image-4-300x194.jpg
                       [width] => 300
                       [height] => 194
                       [mime-type] => image/jpeg
                   )
               [large] => Array
                   (
                       [file] => press_image-1024x665.jpg
                       [width] => 1024
                       [height] => 665
                       [mime-type] => image/jpeg
                   )
               [post-thumbnail] => Array
                   (
                       [file] => press_image-624x405.jpg
                       [width] => 624
                       [height] => 405
                       [mime-type] => image/jpeg
                   )
           )
       [image_meta] => Array
           (
               [aperture] => 5
               [credit] => 
               [camera] => Canon EOS-1Ds Mark III
               [caption] => 
               [created_timestamp] => 1323190643
               [copyright] => 
               [focal_length] => 35
               [iso] => 800
               [shutter_speed] => 0.016666666666667
               [title] => 
           )
   )

wp_get_attachment_metadata() 示例

历史

添加于 版本: 2.1.0

wp_get_attachment_metadata() 历史

源文件

wp_get_attachment_metadata() 函数的代码位于 wp-includes/post.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve attachment meta field for attachment ID.
 *
 * @since 2.1.0
 *
 * @param int  $post_id    Attachment ID. Default 0.
 * @param bool $unfiltered Optional. If true, filters are not run. Default false.
 * @return mixed Attachment meta field. False on failure.
 */
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;

	/**
	 * Filter 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 );
}

wp_get_attachment_metadata() 源文件

相关