When i upload the image from wp_media, this below code runs:
add_action('add_attachment', 'auto_post_after_image_upload'); // WordPress Hook
function auto_post_after_image_upload($attachId)
{
$attachment = get_post($attachId);
$image = wp_get_attachment_image_src( $attachId, 'large');
$image_tag = '<p><img src="'.$image[0].'" /></p>';
$postData = array(
'post_title' => $attachment->post_title,
'post_type' => 'post',
'post_content' => $image_tag . $attachment->post_title,
'post_category' => array('0'),
'post_status' => 'publish',
'post_date' => get_the_time()
);
$post_id = wp_insert_post($postData);
// attach media to post
wp_update_post(array(
'ID' => $attachId,
'post_parent' => $post_id,
));
set_post_thumbnail($post_id, $attachId);
return $attachId;
}
Now i want to put the date of the image when it was created and not the today’s date. How can i do that? get_the_time() returns the today date. I want the selected image created date.
<img src="https://i.stack.imgur.com/E7aYi.png" alt="Created date from image properties
“>
You can use this php function exif_read_data