Target Field Station and Snow Plows
Snow plows in Minneapolis and Target Field Station.Note:This image is…
// update-original-upload-date.php
// Run with: wp eval-file update-original-upload-date.php --allow-root
function update_original_upload_date() {
// Query posts with featured images
$posts = get_posts([
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => [
[
'key' => '_thumbnail_id',
'compare' => 'EXISTS'
]
]
]);
foreach ($posts as $post) {
$content = $post->post_content;
// Skip if FooGallery or Meow Gallery present
if (has_shortcode($content, 'foogallery') || has_shortcode($content, 'meow-gallery')) {
continue;
}
// Count images in content
preg_match_all('/]+>/', $content, $matches);
if (count($matches[0]) !== 1) {
continue;
}
// Get featured image path
$thumb_id = get_post_thumbnail_id($post->ID);
if (!$thumb_id) {
continue;
}
$file = get_attached_file($thumb_id);
if (!$file || !file_exists($file)) {
continue;
}
// Extract EXIF
$exif = @exif_read_data($file, 'EXIF', true);
if (empty($exif['EXIF']['DateTimeOriginal'])) {
continue;
}
$datetime = $exif['EXIF']['DateTimeOriginal'];
// Normalize EXIF format "YYYY:MM:DD HH:MM:SS"
$dt = DateTime::createFromFormat('Y:m:d H:i:s', $datetime);
if (!$dt) {
continue;
}
$formatted = $dt->format('Y-m-d H:i:s');
// Update custom field
update_post_meta($post->ID, 'original_upload_date', $formatted);
// Removed echo to avoid cluttering Post admin page
}
}
update_original_upload_date();