Forums

[resolved] zero dates after running UPDATE funtion (3 posts)

  1. boutwell
    Member
    Posted 5 years ago #

    I have multiple authors that I run a "mass approval" query to posts all of their entries once a week:

    UPDATE wp_posts SET post_status = 'publish' WHERE post_status = 'draft';

    This has a very strange side effect though. The posts dates all become "0000-00-00 00:00:00" only on the entries effected by the querey. Running a second querey:

    UPDATE wp_posts SET post_date = '2006-10-22 19:00:00' WHERE post_date = '0000-00-00 00:00:00';

    ...does correct the problem, but why is this happening in the first place? I would aprove the posts manually if I could, but there are typically over 100 of them so its pretty tiresome.

    Any ideas?

    Thanks!

    Boutwell

  2. Otto
    Tech Ninja
    Posted 5 years ago #

    The timestamp of a post is not generally set until the post is actually published. Drafts get a zero timestamp, as you may have noticed. The reasoning here is that somebody may work on a draft for a long time, and would probably not want to have it backdated to the time they started working on it when they actually decide to publish it.

    I would change your update query to set the post_date and post_date_gmt to the current time (and current GMT time) at the time you publish the post. Yes, it makes your query a bit more complex...

  3. boutwell
    Member
    Posted 5 years ago #

    Ahhh..I was not aware of that. In that case, I will just continue with the two queries. Its only a few extra seconds and when I experiment with sql, I tend to break things :)

    Thanks very much for the resonse, Otto.

    Boutwell

Topic Closed

This topic has been closed to new replies.

About this Topic