• Resolved Sharon

    (@shpemu)


    Hi there. I absolutely adore this plugin. You have made organizing photos so much easier than I ever thought possible. Thank you!

    Having said that, I wanted to assist in an issue I’ve tried to tackle quite a few times. Tonight, with the help of your 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 entered a Field Title of “Date Taken”.
    • The EXIF/Template Value was set to template:([+exif:DateTimeOriginal,date('Y-m-d H:i:s')+])
    • Priority was set to “EXIF”.
    • Existing Text was set to “Replace” (this is a preference, not a requirement).

    I then clicked “Add Rule” and then “Map All Attachments, Custom Fields Now” button, and my dates were entered!

    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… ??

    https://www.ads-software.com/plugins/media-library-assistant/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for the positive feedback and for sharing your approach to modify the WordPress “upload date”. This has come up before (3 years ago, in fact):

    Modify upload date?

    The above topic explains my position on messing with WordPress fields. It also contains a link to another plugin you could use to accomplish your goal without using phpMyAdmin scripts, but I see you’ve already found the “Modify Attachments Meta” plugin on your own. Note that I have not tested that plugin or had any experience with it.

    It seems to me that once you’ve set up a custom field such as “Date Taken” you can just use that as-is.

    Regarding your “only wish now”, I have similar reservations about plugins such as Media Library Plus (MLP) that do not use the WordPress file upload process in its entirety. For example, you can use MLP to upload files to “older” WordPress directories (e.g., your 2015/09 example) but it will still set the post/upload date to the current date and time. Here’s a topic with a link to another plugin you could use in a similar fashion:

    Ftp support?

    WordPress uses the file system for Media Library item storage, but implements all of its organization features in the database. My own experience has been that ignoring the file system has been easier than trying to manually organize things and synch them with the database.

    There are other plugins that implement “folders” within the database using hidden taxonomies or custom fields. Here are earlier topics about that subject you might find useful:

    Conflict with JoomlaUnited WP Media Folder

    Incompatibility with WP Media Folder

    I am also working on better compatibility with:

    WP Real Media Library – Media Categories / Folders

    I hope the above remarks and links give you more insight on MLA’s philosophy and implementation. I am always looking at ideas for new MLA features, but I don’t have plans to add anything that supplements or circumvents WordPress file handling at this point.

    I am marking this topic resolved simply because your question has been answered. I hope you can find what you need for your application with other plugins or by following WordPress conventions. Thanks for your interest in MLA and for sharing your experience.

    Thread Starter Sharon

    (@shpemu)

    I actually wrote this entry after finding that 3-year-old post, in an effort to expand on it a bit. I agree with you that interfering with the WordPress file system can be detrimental, so I’m happy to leave it alone.

    Thanks again for creating such a wonderful plugin. I too am happy to consider this post resolved. ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to map Image Date to Upload Date’ is closed to new replies.