How to set expiration date for your blog post in WordPress?

This wordpress tip comes to your rescue when you want a certain blog post to show only for a limited period of time like a contest or may be a discount offering post. Instead of manually removing the blog post, you can just make it expire automatically.All you need to do is replace your WordPress Loop with this code:

<?php
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 exemple...
             the_title();
             the_excerpt();
         }
     endwhile; endif;
    ?>

 

To create a post with date/time expiration, just create a custom field.
Give it expiration as a key and your date/time (format: mm/dd/yyyy 00:00:00) as a value.
The post will not show after that time stamp.

June 15, 2012

1 responses on "How to set expiration date for your blog post in Wordpress?"

Leave a Reply

top
Template Design © VibeThemes. All rights reserved.

Privacy Preference Center

Necessary

This cookie is set when you login to your account at VibeThemes. VibeThemes based on WordPress sets this cookie, which indicates when you're logged in, and who you are, for most interface use.

WordPress uses the two cookies to bypass the password entry portion of wp-login.php. If WordPress recognizes that you have valid, non-expired cookies, you go directly to the WordPress Administration interface. If you don't have the cookies, or they're expired, or in some other way invalid (like you edited them manually for some reason), WordPress will require you to log in again, in order to obtain new cookies.

wordpress_logged_in_[hash],wp-settings-{time}-[UID]

Advertising

Analytics

Comments

When you comment on VibeThemes blog, they too get cookies stored on their computer. This is purely a convenience, so that the visitor won't need to re-type all their information again when they want to leave another comment.
The commenter cookies are set to expire a little under one year from the time they're set.

comment_author_{HASH},comment_author_email_{HASH},comment_author_url_{HASH},

%d bloggers like this: