I'm running through a normal loop on one of my templates, and it displays a list of upcoming events with dates. I'd like the events that have passed to stay active, but not appear in my list of posts.
As it currently stands, I select a date for the event (custom field), compare that to the current date via PHP date function, and then if its passed, "continue" so we skip the loop. This is great, except my posts per page suffers from this. I'm not using a WP_Query
loop, this is an archive template.
Code looks something like this:
if( have_posts() ) : while( have_posts() ) : the_post();
// Post specific fields
$date = get_post_meta( get_the_ID(), 'Date', true );
$time = get_post_meta( get_the_ID(), 'Time', true );
$cat = wp_get_object_terms(get_the_ID(), 'event-type');
$todaysDate = date('n\/d\/Y');
if( $date < $todaysDate ){
continue;
}
Any ideas on how I can accomplish this another way?
pre_get_posts
. also, your date format should beyyyy/mm/dd
to correctly order by date.