paulwillen
Member
Posted 1 year 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
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
paulwillen
Member
Posted 1 year 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.
paulwillen
Member
Posted 1 year ago #
Oh, I'm not using this code in a template file, but in a plugin.
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
paulwillen
Member
Posted 1 year 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...