Automatically expire posts

Wpsnipp – Adding this PHP code to your wordpress theme will allow you to auto expire posts. This does not delete the post however it prevents the post from being displayed within the loop. Create a custom field key called expiration with a date formatted like this mm/dd/yyyy 00:00:00.

 

 

 

<?php
if (have_posts()) :
while (have_posts()) : the_post(); ?>
$expirationtime = get_post_custom_values('expiration');
if (is_array($expirationtime)) {
$expirestring = implode($expirationtime);
}
$secondsbetween = strtotime($expirestring)-time();
if ( $secondsbetween > 0 ) {
// For example…
the_title();
the_excerpt();
}
endwhile;
endif;
?>

Be Sociable, Share!

Leave a comment