Set post expiration dates

If you are running a time limited contest or offering a discount, for example, you will need to expire the post at a specific time. You can manually remove the article or you can make it expire automatically.

All you need to do is replace your WordPress Loop with this code:

if (have_posts()) :
while (have_posts()) : the_post(); ?>
$expirationtime = get_post_custom_values(‘expire’);
if (is_array($expirationtime)) {
$expirestring = implode($expirationtime);
}

$secondsbetween = strtotime($expirestring)-time();
if ( $secondsbetween > 0 ) {
// For example…
the_title();
the_excerpt();
}
endwhile;
endif;
?>

Once you have done that, you can use custom fields to set the expiration date.
The key for this is ‘expire’ and use the the following date format: mm/dd/yyyy 00:00:00

Please note – This does not remove or un-publish the article, instead it just excludes the article from being displayed in the loop.

Leave a comment

You must be logged in to post a comment.