Some days ago the phone rang and the client asked me why their WordPress blog posts where showing in the inverted order.
Well my answer was something like ‘you just entered them in the reverse order so this is perfectly normal’.
And then tears were shed through the phone itself.
Since I can’t swim, I decided to fix the wrong posts order without asking the client to manually change all the dates.
Here’ how I programmatically reverse the posts dates in WordPress:
You need to call this code only once… you can choose to call it from the CLI, or from a ‘secret’ page in your WordPress website.
- change the MY_CUSTOM_POST_TYPE constant to your post type: ‘post’ is the default type for posts (you don’t say?)
- uncomment the wp_update_post() if you’re happy with the date substitution.
I know this code is ugly… but honestly… It works, I don’t care.