| Category: Web Design
I have tons of photos and would love to organize them, but most plugins seem to have more than I need. I would rather improve my media library rather than install something that saves photos in a completely separate area.
Hi there. I absolutely adore this plugin called Media Library Assistant. It makes organizing photos so much easier than I ever thought possible. A big thank-you to David Lingren for creating such a genius piece of code!
Having said that, I wanted to assist in an issue I’ve tried to tackle quite a few times:
Convert the Upload Date to match the Photo’s Creation Date
Tonight, with the help of this plugin, I was successful! Please note, anyone who tries this, it is not for the faint of heart, as it required me to go into my database via PHPMyAdmin and make changes with a SQL statement (a harmless statement, but you have been warned). I highly recommend backing up your database just in case before trying this. 🙂
OK, here goes. I’ve wanted the upload date to match the photo date ever since I uploaded my first photo to WordPress when it was already past the date it was taken (which is forever). With the help of MLA, I was able to map the creation date, then update the upload date to match the newly saved creation date. Here’s how I did it:
Under Settings > Media Library Assistant, I went to the IPTC/EXIF tab and created a new mapping. These settings belong under Add a new Field and Mapping Rule:
I then clicked “Add Rule” and then “Map All Attachments, Custom Fields Now” button, and my dates were entered! Below is what my settings look like for this item:
Next, I had the problem of getting that date into the upload date field. Here’s where the tricky stuff starts to happen.
The post information is inside the “wp_posts” table, while the data for each post is inside the “wp_postmeta” table. So, the date is saved in one and displayed from the other. Here’s the SQL statement I wrote:
UPDATE `wp_posts`, `wp_postmeta` SET `wp_posts`.`post_date` = `wp_postmeta`.`meta_value`, `wp_posts`.`post_date_gmt` = CONVERT_TZ(wp_postmeta.meta_value,'+00:00','+04:00') WHERE `wp_posts`.`ID` = `wp_postmeta`.`post_id` AND `wp_posts`.`post_type` = 'attachment' AND `wp_postmeta`.`meta_key` = 'Date Taken';
Note that what you’re telling the database to do is find the new Field Title (that’s the “meta_key” in the wp_postmeta table), take that date, and then update “post_date” in the wp_posts table to match. Then, since I’m in the EST time zone, change the “post_date_gmt” field to add four hours. Lastly I tell it to only do this with items that are attachments (this keeps it from accidentally updating a post). It worked like a charm!
My only wish now is that I could do something similar to what Media Library Plus has available, which is allowing someone to upload images into any directory within wp_content/uploads. I ask for this, because I’d like my images from September 2015 to show up in the 2015/09 directory without me having to do it manually. If only there were a bit of code for that as well…. Maybe I’ll have a part 2 covering that bit 🙂