How to auto expire posts in WordPress without plugin

You can set auto expire option for posts in WordPress by adding following code to your theme. The code will not delete you posts but prevents it from displaying within a loop. For doing this you need to create a custom field called expiration with a date formatted like 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;
    ?>

Related posts:

HTML5 page structure

HTML5 offers more powerful structure comparing to older versions of Html. There are many new …


Partner with Us

We are providing an exclusive partnership offer to individuals and companies who are interested in setting up their own web design & development company. For more information about how to partner with us, please contact us