返回介绍

wp_get_attachment_metadata()

发布于 2017-09-11 11:59:29 字数 5537 浏览 1038 评论 0 收藏 0

wp_get_attachment_metadata( int $post_id,  bool $unfiltered = false )

Retrieve attachment meta field for attachment ID.


description


参数

$post_id

(int) (Required) Attachment ID. Default 0.

$unfiltered

(bool) (Optional) If true, filters are not run.

Default value: false


返回值

(mixed) Attachment meta field. False on failure.


源代码

File: 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 );
}

更新日志

Versiondescription
2.1.0Introduced.

相关函数

Uses

  • wp-includes/plugin.php: apply_filters()
  • wp-includes/post.php: wp_get_attachment_metadata
  • wp-includes/post.php: get_post_meta()
  • wp-includes/post.php: get_post()

Used By

  • wp-includes/widgets/class-wp-widget-media-image.php: WP_Widget_Media_Image::render_media()
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::import_theme_starter_content()
  • wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php: WP_REST_Attachments_Controller::prepare_item_for_response()
  • wp-includes/media.php: wp_make_content_images_responsive()
  • wp-includes/media.php: wp_get_attachment_image_srcset()
  • wp-includes/media.php: wp_get_attachment_image_sizes()
  • wp-includes/media.php: wp_calculate_image_sizes()
  • wp-admin/includes/image-edit.php: wp_restore_image()
  • wp-admin/includes/image-edit.php: wp_save_image()
  • wp-admin/includes/image-edit.php: wp_image_editor()
  • wp-admin/includes/media.php: edit_form_image_editor()
  • wp-admin/includes/media.php: attachment_submitbox_metadata()
  • wp-admin/includes/media.php: get_media_item()
  • wp-admin/includes/post.php: edit_post()
  • wp-admin/includes/ajax-actions.php: wp_ajax_save_attachment()
  • wp-admin/includes/meta-boxes.php: attachment_id3_data_meta_box()
  • wp-admin/custom-header.php: Custom_Image_Header::step_2()
  • wp-includes/theme.php: get_uploaded_header_images()
  • wp-includes/post-template.php: prepend_attachment()
  • wp-includes/media.php: wp_maybe_generate_attachment_metadata()
  • wp-includes/media.php: wp_prepare_attachment_for_js()
  • wp-includes/media.php: gallery_shortcode()
  • wp-includes/media.php: wp_playlist_shortcode()
  • wp-includes/media.php: image_get_intermediate_size()
  • wp-includes/media.php: wp_get_attachment_image()
  • wp-includes/media.php: image_downsize()
  • wp-includes/post.php: wp_delete_attachment()
  • wp-includes/post.php: wp_get_attachment_thumb_file()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::_prepare_media_item()
  • Show 24 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Example return value

    
    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
    		 => 
    		[created_timestamp] => 1323190643
    		[copyright] => 
    		[focal_length] => 35
    		[iso] => 800
    		[shutter_speed] => 0.016666666666667
    		[title] => 
    	)
    )
    
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文