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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.