Updated March 2011: Wordpress post expiration code

/ Published in: PHP
Save to your folder(s)

This is an updated version of the original Wordpress post expiration code (<a href="http://snipplr.com/view/3899/wordpress-post-expiration-code/">3899</a>) that bugs out towards the end/beginning of a month when using European date format (d.m.Y). Usage is the same, this code makes "expired" posts cease to show up in the normal page, but they should still show up in the archives. When writing the post, enter a custom field with the key "expiration" and set the date. The below code will go on the index page in the theme folder.

I've changed the way dates are compared using <a href="http://www.highlystructured.com/comparing_dates_php.html"> this article</a> for reference.

Anomalies handling:

- If there is no expiry date set, a post will show up until 2050.
- If the expiration field has a value that can't be converted to Unix timestamp, it will be empty and thus smaller than today's date, i.e. the post won't show up on the home page.

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.