Inspiration For Creative Minds
Home » Labs » How to auto expire posts in WordPress without plugin  

Filed under Labs

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.

	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…
It's only fair to share...Share on Google+Tweet about this on TwitterShare on Facebook

Posts you may like: