您可以使用wp_generate_attachment_metadata
:
此函数用于生成图像附件的元数据。它还会根据Settings\\u Media\\u屏幕上定义的大小创建图像附件的缩略图和其他中间大小。
筛选器的第二个参数是附件ID,因此添加post meta应该不会有问题:
add_filter( \'wp_generate_attachment_metadata\', \'manipulate_metadata_wpse_91177\', 10, 2 );
function manipulate_metadata_wpse_91177( $metadata, $attachment_id )
{
// var_dump( $metadata[\'image_meta\'] );
// Credit is inside $metadata[\'image_meta\'][\'credit\']
return $metadata;
}
检查内容
$metadata[\'image_meta\']
使用FireHP,结果如下:
aperture: 4
camera: "DMC-FZ100"
caption: ""
copyright: ""
created_timestamp: 1352136868
credit: ""
focal_length: "9.2"
iso: "100"
shutter_speed: "0.003125"
title: "Double Dip"
<小时>
[Update]在媒体库屏幕中添加自定义列的完整测试(
/wp-admin/upload.php
) 要显示帖子元信息,请执行以下操作:
add_filter( \'wp_generate_attachment_metadata\', \'manipulate_metadata_wpse_91177\', 10, 2 );
add_filter( \'manage_upload_columns\', \'camera_info_column_wpse_91177\' );
add_action( \'manage_media_custom_column\', \'camera_info_display_wpse_91177\', 10, 2 );
function manipulate_metadata_wpse_91177( $metadata, $attachment_id )
{
update_post_meta( $attachment_id, \'photo_title\', $metadata[\'image_meta\'][\'title\'] );
update_post_meta( $attachment_id, \'photo_camera\', $metadata[\'image_meta\'][\'camera\'] );
return $metadata;
}
function camera_info_column_wpse_91177( $columns )
{
$columns[\'cam_info\'] = \'Camera Info\';
return $columns;
}
function camera_info_display_wpse_91177( $column_name, $post_id )
{
if( \'cam_info\' != $column_name || !wp_attachment_is_image( $post_id ) )
return;
$title = get_post_meta( $post_id, \'photo_title\', true );
$camera = get_post_meta( $post_id, \'photo_camera\', true );
$echo_title = $title ? \'Title: \' . $title . \'<br />\' : \'\';
$echo_camera = $camera ? \'Camera: \' . $camera : \'\';
echo $echo_title . $echo_camera;
}
相关问题;答:
Create new category upon save based on post information