Return to Snippet

Revision: 15235
at June 28, 2009 09:54 by gjindancer


Initial Code
***PUT THIS INSIDE THE LOOP, FIRST THING***

<?php  //to check against expiration date; 
$timestamp = strtotime("now + 8 hours");  
$currentdate = date('YmdHis', $timestamp);
$expirationdate = get_post_custom_values('expiration');
if (is_null($expirationdate)) {	
  			$expirestring = '30005050235959'; //MAKE UN-EXPIRING POSTS ALWAYS SHOW UP;
} else { 
  
if (is_array($expirationdate)) {	
  						$expirestringarray = implode($expirationdate);	
						}
$markup = array("/",":"," ");
$expirestring = str_replace($markup,"",$expirestringarray);
} //else 
if (( $expirestring > $currentdate ) || (is_archive())) { ?>

***THEN PUT THE FOLLOWING LINE AT THE VERY END OF THE LOOP*** 

<?php } //end if for expiration; ?>

Initial URL
http://www.nrbet.com/

Initial Description
All you need to do when writing the post, is enter a custom field with the key "expiration" and set the value in the format: "2010/01/01 18:20:00" - this would expire the post at 6.20pm on the 1st January 2010.

Initial Title
Updated: Wordpress post expiration code

Initial Tags
php, wordpress

Initial Language
PHP