What is considered the post’s creation date for wp_insert_post?

The short answer is, post_date and post_date_gmt will be set to the date you scheduled the post to be published – not the date you created the post -, so post_date and post_date_gmt are holding the publishing date.


Update:

As reply to comment:

  1. When will the wp_insert_post hook be triggered?

    • Actually both times, so on clicking Schedule and on the scheduled change of the post status from future to publish.
    • Why? Firstly because:
    • And secondly because it is part of:
    • Which gets triggered by:
    • Take a closer look at the documentation(s) and getting to know the source code, here mainly post.php, always helps to understand what’s really happening.
  2. Can/should you use the function time()?

    • You certainly can, take the new information from 1. into consideration.
    • If you should depends on the fact, is the information you need already available. If it is, then there is no reason to get the same information twice.
    • So if post_date and post_date_gmt hold the information you need, which would be, as it has been established, the publishing date, use it.
    • Or use post_modified and post_modified_gmt if you want to reflect changes.

The actual approach you’ll going to chose really depends on your needs/plans, which I know little about. As far as I can tell one thing you definitely should consider is using another hook – or hooks. Take a look at Post Status Transitions for other ones to consider. Additionally inspect the source – post.php – to get deeper into when and how those are hooks used. There are many questions about this on here, just search for it.

Leave a Comment