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:
-
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:
- The function
wp_insert_post()
is invoking the hook itself – see source;
- The function
- And secondly because it is part of:
wp_publish_post()
– see source;
- 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.
-
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
andpost_date_gmt
hold the information you need, which would be, as it has been established, the publishing date, use it. - Or use
post_modified
andpost_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.