Add an expration date for posts!

If you want to add an expration date to your posts you have to change your WordPress’ Loop area. This is not delete your posts, only turns to draft. When you change Loop area you will able to add an expration date with custom fileds. This is very simple function/recipe.Firstly you have to change your Loop area. You have to change your theme files for this. Every Loop area must change.

Change your Loop area wtih this code.

<?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;
?>

After apply this code you can add a custom filed, the name of custom filed is expration. The custom fileds value must be like mm/dd/yyyy 00:00:00.

That’s All! Have a nice day!


Related posts:

Jul 19th, 2009 | Posted in Wordpress
If you enjoyed this post, make sure you subscribe to my RSS Feed
Comments are closed.
Highslide for Wordpress Plugin