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().

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

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