FerdieQO
Well-known member
- Joined
- Jul 15, 2016
- Messages
- 222
- Points
- 28
This WordPress tip becomes very useful when you are running a short-term promotion that does not want it to stay forever. Instead of manually removing posts, you can set the calendar to stop itself from appearing. You can apply this to an article on your site. You post it on your blog, but you do not want this program to stay on your blog after the program ends. So you can remove it automatically with this code.
All you need to do is replace your WordPress Loop with this code:
Then you can use custom fields when writing a post to set expiration dates. Make sure the "Expiration" key and use the following date format: mm / dd / yyyy 00:00:00
This WordPress technique does not remove or unpublish posted posts; it just does not let the post show up on feed anymore.
All you need to do is replace your WordPress Loop with this code:
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 example…
the_title();
the_excerpt();
}
endwhile;
endif;
?>
This WordPress technique does not remove or unpublish posted posts; it just does not let the post show up on feed anymore.