WordPress change post_date for tests

If you want to create a post via the post factory in you tests you can do it like this:

Make sure to pass a date! Unix timestamps or other formats won’t work.

This creates 2 posts with different dates. You can test the function getPostsInYear(2014) as follows:

Post1 should not be returned by getPostsInYear( 2014 ) because it was posted in 2010 so we cover this by assertNotContains().

If you have found a spelling error, please, notify us by selecting that text and pressing Ctrl+Enter.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Spelling error report

The following text will be sent to our editors: