Update post meta data with IPTC during upload of media
-
Hello,
I am created a SIRI shortcut to upload photos from Lightroom CC on my iPad via REST API (the provided API from wordpress) to the media library of WordPress. This works fine. But now I would like to see that the post meta (title, alt, caption, description) are filled with the EXIF/ITPC data of the photo.
I don’t want to use a plugin and read something in the documentation and learned that I can get all stored metadata from the function wp_read_image_metadata( $attachment_path ).
So I’ve created a function and add an add_action call:
add_action( 'add_attachment', 'my_set_image_meta_upon_image_upload' ); function my_set_image_meta_upon_image_upload( $post_ID ) { if ( wp_attachment_is_image( $post_ID ) ) { $attachment_path = get_attached_file( $post->ID ); $metadata = wp_read_image_metadata( $attachment_path ); $my_image_title = $metadata["title"]."-title"; $my_image_meta = array( 'ID' => $post_ID, 'post_title' => $my_image_title, 'post_excerpt' => $my_image_title, 'post_content' => $my_image_title ); update_post_meta( $post_ID, '_wp_attachment_image_alt', $my_image_title ); wp_update_post( $my_image_meta ); } }
But the metadata object seems to be empty. My suspicion is that the action isn’t the right one and that at this time the metadata not written. But what is the right way to do this? What is the right hook or action to do this?
Thanks in advance
Thorsten
- The topic ‘Update post meta data with IPTC during upload of media’ is closed to new replies.