WordPress.org

Ready to get started?Download WordPress

Forums

Get Published Date and Time (7 posts)

  1. paulwillen
    Member
    Posted 3 years ago #

    Hi,

    I'm trying to get the original published date and time from a post.
    Normally you'd say I can use

    $the_post = get_post($post_ID);
    $dateline = $the_post->post_date;

    But when updating a post the post_ID changes and the post_date I get is from the revision, and not from the published post.

    I've tried to get arround this with the
    get_post_ancestors($the_post);
    but sadly have no clue how to go from there...

    Is there a way to get the original publish date from the post on a revision?

    Thanks and best regard,

    Paul

  2. Edward Caissie
    Theme Review Admin
    Posted 3 years ago #

    If you are doing this from within the_Loop

    the_time()

    returns the original post date ... have a look at this page for some more details: http://codex.wordpress.org/Function_Reference/the_time

  3. paulwillen
    Member
    Posted 3 years ago #

    Hi,

    Thanks for your comment, but sadly I dont Use the_loop.
    I get a post by:

    $the_post = get_post($post_ID);
    So I don't loop through my posts.
    Is there any way around using the_time() without using the_loop?

    Because that would solve my problem I think.

  4. paulwillen
    Member
    Posted 3 years ago #

    Oh, I'm not using this code in a template file, but in a plugin.

  5. Edward Caissie
    Theme Review Admin
    Posted 3 years ago #

    Have you considered a one-post loop for your plugin using wp_query to set the specific post?

    Additional Reference: http://codex.wordpress.org/Function_Reference/WP_Query

  6. paulwillen
    Member
    Posted 3 years ago #

    Hi Cais.

    Thanks for following up with me. I really appreciate that!
    I was able to solve my problem with this:

    $origpostdate = get_the_date($d, $the_post->post_parent);
    		$origposttime = get_the_time($d, $the_post->post_parent);
    		$dateline = $origpostdate.' '.$origposttime;

    It might not be the best solution, but it works without any problems for me.

    Thanks again...

  7. Edward Caissie
    Theme Review Admin
    Posted 3 years ago #

    Nicely sorted out.

Topic Closed

This topic has been closed to new replies.

About this Topic