• Resolved amyls

    (@amyls)


    Since upgrading from WordPress 4.7.2 to WordPress 4.7.3, every time I click ‘Publish’ on a draft post, the post shows a publication date of October 27, 2016. My post does then appear to publish, but I have to manually override that date with today’s date and time before the published post will become publicly visible on my site. (October 27th 2016 may have been the date I created the draft because I work an average of around 6 months ahead of my post publication schedule.)

    I could continue working with my blog by manually altering the date each time I publish a draft post, but I can’t understand why it initially reverts to a publication date that is in the past. Is anyone able to tell me how to fix this?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Does each draft use that specific date (Oct 27, 2016) no matter when you create it? Or, it uses the correct date when the draft was created as the publishing date? So if draft was created Dec 15, 2016 it will use that date instead of Mar 26, 2017.

    Just want to clarify.

    ^V

    Thread Starter amyls

    (@amyls)

    Thanks for your response! It uses the date the draft was created. Yesterday, I published a post I drafted back in November and that was the publication date it used. I had to change the date manually to yesterday’s date to make the post appear at the top of my new posts where my readers can see it.

    • This reply was modified 9 years, 1 month ago by amyls.

    Ok good, this is default behavior not an issue. So now we simply need to update the date to the correct one when you publish posts. We do that with this code, which should be put into your theme’s functions.php file:

    function post_published_date( $post )   
    {  
        // Apply this to posts only 
        if ($post->post_type == 'post')   
        {  
            // Update the date 
            $pub_post = array(  
                'ID'            => $post->ID,  
                'post_date'     => date("Y-m-d H:i:s"),  
                'post_date_gmt'     => date("Y-m-d H:i:s")  
            );  
          
            // Update database  
            wp_update_post( $pub_post );  
        }  
    }  
    add_action( 'draft_to_publish', 'post_published_date' );

    When you hit Publish, this will automatically update your date. If this solves your issue, don’t forget to mark this topic as resolved. Thanks 🙂

    ^V

    Thread Starter amyls

    (@amyls)

    Thank you so much for the code and for your assistance. I have pasted the code into the functions.php file but the publication date on my pre-existing draft posts is still listed as the date they were created and will still have to be manually changed when I publish those posts.

    Will the code only prevent this from occurring in new draft posts that I create after adding the code?

    @amyls

    Happy to help. The code snippet should work on any posts in draft status that are published. It uses built-in hook that WordPress provides “draft_to_publish”. So when a draft is published, it takes on published date instead of original draft date.

    I tested it on a draft I had created in March, and when I hit “publish” it used April 1 as the published date.

    Does your setup use anything custom like a custom post status maybe?
    Do you usually hit “publish” button inside post edit screen? Or use some other method to publish them?

    ^V

    Thread Starter amyls

    (@amyls)

    I published my first draft blog post yesterday since adding the code and it changed the date for me and published perfectly. Thank you very, very much for solving my problem! You’ve been absolutely fantastic and I appreciate it more than I can say.

    @amyls You’re welcome! I’m happy to hear that this worked for you. Do mark this topic as solved please, so others know this has been resolved 🙂

    ^V

    Thread Starter amyls

    (@amyls)

    Done. 🙂 Thanks again!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Problem since upgrading to WordPress 4.7.3’ is closed to new replies.