Jump to content

How To Archive Post in Wordpress


cdogstu99

Recommended Posts

I have a website which lists deals that expire. Each deal has a custom field with an expiration date. I'm looking to somehow archive the posts when they expire, yet still have them available if you access the link to the deal (since i don't lose SEO impact). I also would like to have them disappear from the category they are held in.

 

I tried this code in my home page (loop) and also put the same code in my category page loop.

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

 

 

I was able to have the expiring posts disappear from the home page and archived, but the listing still remained in the category the deal is posted in. Anyone know how to do this?

 

Link to comment
https://forums.phpfreaks.com/topic/206518-how-to-archive-post-in-wordpress/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.