I'm trying to use the following code to not show expired posts by date through custom fields . So far it worked, the posts out of the categories. Now how do I display only the posts expired?
Reference: http://debbieteakle.com/2011/11/add-an-expiry-date-to-wordpress-posts
<?php query_posts('cat=4,1'); ?> //my custom query for categories 4 & 1
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- expiry code below -->
<?php
$currentdate = date("Ymd");
$expirationdate = get_post_custom_values('expiration');
if (is_null($expirationdate)) {
$expirestring = '30001212'; //Set future date to posts with expiry.
} else {
if (is_array($expirationdate)) {
$expirestringarray = implode($expirationdate);
}
$expirestring = str_replace("/","",$expirestringarray);
} //else
if ( $expirestring > $currentdate ) { ?>
<!--end expiry code-->
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<!-- thumbnail code below -->
<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>
<?php } else { ?>
<?php } ?>
<!--end thumbnail code-->
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to
<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<p>Posted on <?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></p>
<!-- shows excerpts below -->
<?php
global $more;
$more = 0;
?>
<!-- end shows excerpts code -->
<?php the_content('Read the rest of this entry »'); ?>
<p><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> |
<?php edit_post_link('Edit'); ?> </p>
</div>
<?php } ?>
<?php endwhile; endif; ?>
Change greater than operator <
to less than operator >
in if condition. Your code should be like this.
if ( $expirestring < $currentdate ) { ?>
It will display only the posts expired.