5

I suppose getting the first revision of a particular post and get the date, right ?

How to do that?

  • 2
    The post_date and post_date_gmt is the date the post was created on. – Pieter Goosen Feb 4 '15 at 12:41
  • Thank you Pieter, but it seems both give me last modification date. Are you sure ? – Max Feb 4 '15 at 12:44
  • 1
    Then you have a custom filter or function that is modifying your post dates. If a post is modified, that specific date and time is saved as post_modified – Pieter Goosen Feb 4 '15 at 12:46
  • 3
    I am sorry, but i think this is wrong, at least for scheduled posts : post_date is the scheduled date. And there is no filter i directly query database and get the post then call ->post_date. Any idea to get the very first time the post was added to wordpress ? – Max Feb 4 '15 at 12:58
  • I've just tested it : i retrieve post_date from a scheduled post, it gives me the scheduled date. Not the same for you ? – Max Feb 4 '15 at 13:20
5

The post_date and post_date_gmt serves as the date that the post was created. For scheduled posts this will be the date on which the post is scheduled to be published.

There is no reliable native method to determine the date when a scheduled post was added. For scheduled posts, you can try the post_modified or post_modified_gmt dates as this will correspond when the post was first added. You have to remember, this is unreliable as this date will change when a post is modified

Another (unreliable as well) method, is to use revisions. If you have revisions enabled, when a post is scheduled or published, a post revision is saved. That revision, which will be saved after the scheduled post when the scheduled button is clicked, will hold the current post date on which the scheduled button is clicked. Check the pic below

enter image description here

If you need a reliable way of doing this, you will need to write your own custom function to save the exact time when the scheduled button is clicked to schedule a post

  • 2
    Thank you, but this is strange there is no such a function – Max Feb 27 '15 at 9:32
  • Is such a function really necessary. Your case is very isolated – Pieter Goosen Feb 27 '15 at 9:41
  • 4
    I don't think the case is very isolated, especially now that woocommerce is in the picture and you want to differentiate between the age of products – Kirby Jul 15 '15 at 20:05
  • @Kirby please explain in an answer – Pieter Goosen Jul 15 '15 at 20:34
1

I needed the same info and just figured out by myself. You have to make a custom query to get the first _wp_old_date from the postmeta table as @dipak_pusti suggested. Run the following statement:

global $wpdb;
$post_id = 1234;
$meta_key = '_wp_old_date';
$post_create_date = $wpdb->get_var( $wpdb->prepare(
    "
        SELECT MIN($wpdb->postmeta.meta_value) as post_create_date
        FROM $wpdb->postmeta
        WHERE $wpdb->postmeta.post_id = %d
            AND $wpdb->postmeta.meta_key = %s
    ",
    $post_id,
    $meta_key
) );

if(is_null($post_create_date)) {
    $post_create_date = get_the_date('Y-m-d', $post_id);
}

echo "<p>Post create date is: {$post_create_date}</p>";

Note: If the _wp_old_date is NULL (this means the publish date has never changed) you can use the date from get_the_date('Y-m-d', $post_id).

0

Use get_the_date(); to get the date defined in the meta box "Publish" at the field "Published on ..", this usually is the date the user created the post unless (s)he change it.

0

When I was stuck with same type of case as yours, i found a meta key _wp_old_date with a meta value representing a date.

By Googling this, i found a function is being used to store the old value when a Post or Object is being changed.

https://wpseek.com/function/wp_check_for_changed_dates/

I know, this is very late answer, but it may help others in future. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.