Posted By

gjindancer on 06/28/09


Tagged

php wordpress events expiring posts


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

rickfu
maxvee8


Updated: Wordpress post expiration code


 / Published in: PHP
 

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

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.

  1. ***PUT THIS INSIDE THE LOOP, FIRST THING***
  2.  
  3. <?php //to check against expiration date;
  4. $timestamp = strtotime("now + 8 hours");
  5. $currentdate = date('YmdHis', $timestamp);
  6. $expirationdate = get_post_custom_values('expiration');
  7. if (is_null($expirationdate)) {
  8. $expirestring = '30005050235959'; //MAKE UN-EXPIRING POSTS ALWAYS SHOW UP;
  9. } else {
  10.  
  11. if (is_array($expirationdate)) {
  12. $expirestringarray = implode($expirationdate);
  13. }
  14. $markup = array("/",":"," ");
  15. $expirestring = str_replace($markup,"",$expirestringarray);
  16. } //else
  17. if (( $expirestring > $currentdate ) || (is_archive())) { ?>
  18.  
  19. ***THEN PUT THE FOLLOWING LINE AT THE VERY END OF THE LOOP***
  20.  
  21. <?php } //end if for expiration; ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: cdogstu99 on July 2, 2010

Can someone please tell me how to get this to work on a category page. Was able to get it working for the home page loop, but not for categories. Any ideas?

You need to login to post a comment.