• Resolved Zack Grossbart

    (@zgrossbart)


    I’m working on a plugin that will change the date of individual posts. I’m looking for an API that can change the date of a post given the post ID and a new date. I’ve been looking for this, but I can’t find it.

    Any pointers would be very helpful.

    Thanks,
    Zack

Viewing 3 replies - 1 through 3 (of 3 total)
  • MichaelH

    (@michaelh)

    I’d guess you need Function_Reference/wp_update_post

    Thread Starter Zack Grossbart

    (@zgrossbart)

    Thank you for the help. That was exactly what I was looking for, but I’m having a little trouble with it. I have code that looks like this:

    $updated_post = array();
    $updated_post[‘ID’] = $myID;
    $updated_post[‘post_date’] = $myNewDate;
    $updated_post[‘post_status’] = “publish”;

    wp_update_post( $updated_post );

    The date updates properly, but the status doesn’t seem to change. Is there something extra that I need to do when changing the post status?

    Thanks,
    Zack

    Thread Starter Zack Grossbart

    (@zgrossbart)

    I was able to figure out my own problem. The issue was that I wasn’t setting all the dates and the cron job was fixing up the status. I’m setting all the dates now and everything works.

    Thanks,
    Zack

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Changing the date of a post from PHP’ is closed to new replies.