Opened 5 years ago
Closed 5 years ago
#48923 closed defect (bug) (duplicate)
Permalink Date is GMT Regardless of Time Zone Setting
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | major | Version: | 5.3 |
Component: | Permalinks | Keywords: | |
Focuses: | Cc: |
Description
The date in the WP permalinks is created from a GMT date (see link-template.php):
$date = explode( ' ', gmdate( 'Y m d H i s', $unixtime ) );
This results in a mismatch if a post's local and GMT dates are a different day.
For example, I have a post on my site with a 'post_date' of '2014-05-07 23:57:56' (US Eastern) and a "post_date_gmt" of "2014-05-08 03:57:56". WordPress sets the permalinks with /2014/05/08/(slug) even though it should be /2014/05/07/(slug).
As a result, attempting to visit the page results in a 404 error...because the page query ends up asking for a post on /2014/05/08:
SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND ( ( YEAR( wp_posts.post_date ) = 2014 AND MONTH( wp_posts.post_date ) = 5 AND DAYOFMONTH( wp_posts.post_date ) = 8 ) ) AND wp_et_4_posts.post_name = '((REDACTED))' AND wp_posts.post_type = 'post' ORDER BY wp_posts.post_date DESC
Note that the WP query is checking post_date (not post_gmt_date) even though the permalink was formed using a GMT date.
The preferable fix (in my opinion) is to use local date for both creating and parsing permalinks including the post date...but it would also be acceptable to make them both based on GMT. I think the most important thing is that they match and not throw 404s.
Hi there, welcome to WordPress Trac! Thanks for the report.
The permalink issue is being tracked in #48623, the fix will ship with WordPress 5.3.1.