Make WordPress Core

Opened 5 years ago

Last modified 5 years ago

#48006 new defect (bug)

post_date not as expected

Reported by: marrank's profile marrank Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.2.3
Component: Posts, Post Types Keywords: has-patch has-unit-tests
Focuses: Cc:


I have noticed this when scheduling a post.

1) From wp-admin choose Pages.
2) Add new.
3) Change from publish immediately to selecting time and date.
4) Select a date, for example, 2019-09-09 17:00
5) Save the post.
6) Look in the wp_posts table in the database for the post and the post_date column will be something like 2019-09-09 17:00:21

It is not really as expected since you, as a user, are not able to set which second the page should be published you assume it would be at 00. In this case you expect that is is 17:00:00. The problem is that if you have a scheduled crontab that runs every 5 minutes (*/5) it will get missed schedule the first time since the cron will run at 17:00:00 and the publish time of the post is 17:00:21. From my experience most users choose the schedule at top of the hour so we get this missmatch a lot. For us it would be easier if assumed that it is 00 seconds always.

Attachments (4)

48006.diff (1.1 KB) - added by donmhico 5 years ago.
48006.2.diff (1.9 KB) - added by donmhico 5 years ago.
Added unit test.
Screen Shot 2019-09-10 at 5.40.13 PM.png (107.4 KB) - added by donmhico 5 years ago.
Skärmavbild 2019-09-17 kl. 11.12.23.jpg (40.6 KB) - added by marrank 5 years ago.

Download all attachments as: .zip

Change History (18)

#1 @marrank
5 years ago

  • Summary changed from post_date no as expected to post_date not as expected

5 years ago

#2 follow-up: @donmhico
5 years ago

  • Keywords has-patch added

Hello @marrank. Thank you for the report ticket and welcome to the WordPress trac. I've attached a patch, 48006.diff, that should address the issue.

#3 @SergeyBiryukov
5 years ago

  • Component changed from General to Posts, Post Types

5 years ago

Added unit test.

#4 @donmhico
5 years ago

  • Keywords has-unit-tests added

#5 @marrank
5 years ago


Thanks for looking into this so quickly! The fix does unfortunately not working for me. I see the code, it makes sense what you have done but it does not look like it runs when I am saving the post. So I am still getting current second in my post_date.

#6 @donmhico
5 years ago

Hello @marrank,

Thank you for testing. Can you provide the exact steps you did?

#7 @marrank
5 years ago

Hi! I did the steps 1-6 in the original ticket. Ie logging in to wp-admin and creating a page with a future date. It looks like wp_insert_post is run when i press add new page, but not when I save where is which the future date is set.

Version 0, edited 5 years ago by marrank (next)

#8 @donmhico
5 years ago

Try to look in the screenshot above @marrank. Posts ID 45 and 47 are scheduled and as you can see their seconds are :00.

Just to confirm a few things.

  1. How are you applying the patch? Try to build the source files with the command npm run build to make sure that the changes are applied.
  1. The fix is only applied to the actual post and not with revisions.

#9 @marrank
5 years ago

@donmhico Ok!
1) I manually went inte wp-include/post.php and added it.
2) Ok yes

Have you created those post through wp-admin or through your unit test?

#10 @donmhico
5 years ago

Thanks for your response @marrank. Yes i've tested it manually. The screenshot I gave above is from a manual created post.

Here are my steps.

  1. Go to /wp-admin.
  2. Create a post with Publish: "Immediately" changed to a future time.
  3. Save post.

#11 follow-up: @marrank
5 years ago

Hmm ok yes then we have the same workflow. I guess it could be a plugin or something that is messing it up. I will try with a clean install! Can you also send your post.php for reference?

#12 in reply to: ↑ 11 @jonbakke
5 years ago

Replying to marrank:

Hmm ok yes then we have the same workflow. I guess it could be a plugin or something that is messing it up. I will try with a clean install!

I'm hoping this might be helpful: wp-include/post.php has seen other changes since the latest release, so make sure you're applying the patch to a development copy (such as

#13 in reply to: ↑ 2 @jonbakke
5 years ago

Replying to donmhico:

I've attached a patch, 48006.diff, that should address the issue.

The code comment in the main patch and the unit test name both refer to the top of the "hour". I believe that should be top of the "minute"? I'd be happy to update the patches, if that would help.

#14 @marrank
5 years ago

@donmhico Sorry, but I cant get this to work.

Now I did
1) wp core download --version="nightly"
2) In wp-admin dashboard it says WordPress 5.3-alpha-46152
3) Create post with changed Immediately to a set date.

However when I inspect in database it still uses seconds. Not sure why it not working. @jonbakke Maybe you could try it as well? That would be really helpful for my sanity :-D

Note: See TracTickets for help on using tickets.