Reputation: 11
I'm using the following code to hide posts in the past in wordpress (the date is coming from a custom field I've made called date) - problem is its also hiding ones set to today's date as well
<?php query_posts($query_string.'&posts_per_page=24&order=desc&orderby=meta_value&meta_key=date'); ?>
and
<?php while (have_posts()) : the_post();
$date = get_post_meta($post->ID, 'date', true);
if ($date){
$mydate = "$date";
echo date('l, j F, Y', strtotime($mydate));
}
?>
Any Ideas how to get it to allow posts where the custom field is todays date?
thanks!
Upvotes: 0
Views: 464
Reputation: 538
I ended up using this..
<?php while (have_posts()) : the_post();
//to check against expiration date;
$currentdate = date("Ymd");
$expirationdate = get_post_custom_values('date');
if (is_null($expirationdate)) {
$expirestring = '30005050'; //MAKE UN-EXPIRING POSTS ALWAYS SHOW UP;
} else {
if (is_array($expirationdate)) {
$expirestringarray = implode($expirationdate);
}
$expirestring = str_replace("/","",$expirestringarray);
} //else
if ( $expirestring >= $currentdate ) { ?>
loop goes in here
<?php } ?>
In all honesty I can't remember where I found it - but if someone can neaten it up that would be great!
Upvotes: 0
Reputation: 1
I don't have a specific answer to your question but there are two plugins that do exactly what you are trying to do. I've linked them below.
Simple Expires http://wordpress.org/extend/plugins/simple-expires/
Post Expirator http://wordpress.org/extend/plugins/post-expirator/
Both seem to be exactly what you are trying to accomplish.
I hope this helps.
Upvotes: 0