Make WordPress Core

Opened 7 weeks ago

Last modified 7 weeks ago

#51289 reviewing defect (bug)

Documentation issue: get_post_time is getting the time when published not when created

Reported by: casiepa Owned by: SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: normal Version:
Component: Date/Time Keywords: has-patch
Focuses: docs Cc:


I'm having a doubt with https://developer.wordpress.org/reference/functions/get_post_time/ (probably the same with https://developer.wordpress.org/reference/functions/get_the_date/)
They both say 'Retrieve the date on which the post was written.', but from some programming I'm doing now it looks more like 'Retrieve the date on which the post was PUBLISHED.'.

Test: create a post in draft or pending and check that date using the function. (I'm doing it with a CPT)

Attachments (1)

51289.diff (6.5 KB) - added by audrasjb 7 weeks ago.
Docs: Various date/time functions are returning the date/time the content was published, not written

Download all attachments as: .zip

Change History (6)

This ticket was mentioned in Slack in #docs by casiepa. View the logs.

7 weeks ago

7 weeks ago

Docs: Various date/time functions are returning the date/time the content was published, not written

#2 @audrasjb
7 weeks ago

  • Component changed from General to Date/Time
  • Keywords has-patch added

Thanks for raising this issue Pascal!

I updated the following functions/hooks:

  • the_date_xml
  • the_date
  • get_the_date
  • get_the_modified_date
  • the_time
  • get_the_time
  • get_post_time
  • get_post_modified_time
  • the_weekday
  • the_weekday_date

#3 @SergeyBiryukov
7 weeks ago

  • Milestone changed from Awaiting Review to 5.6
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#4 @SergeyBiryukov
7 weeks ago

This might need some further clarification, as it's not quite clear what "published" means for a draft or pending post.

In my testing:

  • For a draft post that never was published, get_the_date() returns the date of the last edit.
  • For a post that was previously published, get_the_date() returns the published date.

For both of these cases, the existing docs seem accurate. 51289.diff would only be accurate for the second case.

#5 @Rarst
7 weeks ago

The current wording is imperfect, but "was published" would imply a post is published. It might be not published. It might be scheduled for the future.

I think it should be neutral wording like "the date of the current post", which is already partially there. It just describes the return without implications about state of the post.

Last edited 7 weeks ago by Rarst (previous) (diff)
Note: See TracTickets for help on using tickets.