WordPress.org

Make WordPress Core

Opened 5 months ago

Last modified 3 months 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.7 Priority: normal
Severity: normal Version:
Component: Date/Time Keywords: has-patch good-first-bug needs-refresh
Focuses: docs Cc:

Description

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 5 months ago.
Docs: Various date/time functions are returning the date/time the content was published, not written

Download all attachments as: .zip

Change History (8)

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


5 months ago

@audrasjb
5 months ago

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

#2 @audrasjb
5 months 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
5 months ago

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

#4 @SergeyBiryukov
5 months 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
5 months 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 5 months ago by Rarst (previous) (diff)

#6 @helen
3 months ago

  • Keywords good-first-bug needs-refresh added
  • Milestone changed from 5.6 to 5.7

I agree this can be worded as "the date of the post" for most of these, a few seem a little tricker (e.g. "The weekday name of the date of the post"?) but I'm confidence somebody with some wordsmithing skills can figure it out :) Punting out of 5.6 for now, strongly encourage some contributions here.

This ticket was mentioned in Slack in #core by helen. View the logs.


3 months ago

Note: See TracTickets for help on using tickets.