• Resolved Michiel

    (@michiel)


    Is it somehow possible to ensure that the imported attachments get the same time stamp as the corresponding posts? This way they show up nicely by year in the media library. Have been spitting through the code but as PHP beginner I have not been able to find what I should change in order to override the standard upload date/time… Thanks for your help!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Michiel

    (@michiel)

    Think I almost got it, but stuck at one area.

    I did the following:

    Around line 136 I added the following code to determine the parent post post_date. Unfortunately this line does not yet do the trick and I am not able to get the post_date. When I use some test date it works perfect and the test date appears in the media libary post.
    $parentdate = mysql_query("SELECT $wpdb->post_date FROM $wpdb->posts WHERE ID='$p->post_ID'");

    Then (around) line 139 I made a change to distribute $parentdate to the media upload function:
    $id = ex2gal_media_handle_upload('ex2gal', $p->post_ID, $parentdate, $postdata);

    Line 199 included parentdate
    function ex2gal_media_handle_upload($file_id, $post_id, $parentdate, $post_data = array()) {

    Then I added the following in line 227 to get the parent post date in the media upload.
    'post_date' => $parentdate,

    Thread Starter Michiel

    (@michiel)

    mmm… when I use:

    $parentdate = mysql_query("SELECT post_date FROM $wpdb->posts WHERE ID='$p->post_ID'");

    I get back in the image post in the media library:
    0000-00-00 00:00:00

    What is the correct method to get the post_date from the parent post?

    Thread Starter Michiel

    (@michiel)

    Well hey, with some searching in the codex I seem to improve my coding skills:-). Add around line 136 the following line:

    $parentdate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE ID='$p->post_ID'");

    Ulf Benjaminsson: maybe consider the above for a 0.003 release? It makes it so much nice to navigate the images in the media library when they are stored with the correct dates.

    Thread Starter Michiel

    (@michiel)

    To make it perfect change / add the following around 220:
    This will help to ensure “date added” in the media library reflects the date of the parent post.

    // Construct the attachment array
    	$attachment = array_merge( array(
    		'post_mime_type' => $type,
    		'guid' => $url,
    		'post_parent' => $post_id,
    		'post_title' => $title,
    		'post_content' => $content,
    		'post_date' => $parentdate,
    		'post_date_gmt' => $parentdate,
    		'post_modified' => $parentdate,
    		'post_modified_gmt' => $parentdate,
    	), $post_data );
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Exhibit to WP Gallery] set timestamp of imported Exhibit attachments’ is closed to new replies.