Show posts that have a date that is <= to todays date
<?php
$events = new WP_Query( array(
'post_type' => 'events',
'orderby' => 'date',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_date',
'type' => 'NUMERIC', // MySQL needs to treat date meta values as numbers
'value' => current_time( 'Ymd' ), // Today in ACF datetime format
'compare' => '>=', // Greater than or equal to value
),
),
));
$now = time();
?>
<div id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($className); ?>">
<h2>Events</h2>
<?php if ( $events->have_posts() ):
while ( $events->have_posts() ) : $events->the_post(); ?>
<div class="event">
<h5><?php the_title(); ?></h5>
<strong><?php echo get_field( 'event_date', get_the_ID() ); ?></strong>
<div><?php echo get_field( 'event_location', get_the_ID() ); ?></div>
<?php if( get_field( 'event_details', get_the_ID() ) == 'website' ): ?>
<a href="<?php echo get_field( 'event_website_link', get_the_ID() ); ?>" target="_blank">Event Details</a>
<?php endif; ?>
<?php if( get_field( 'event_details', get_the_ID() ) == 'pdf' ): ?>
<a href="<?php echo get_field( 'event_pdf', get_the_ID() ); ?>" target="_blank">Event Details</a>
<?php endif; ?>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata();
endif; // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<p><a href="https://www.mypcnow.org/resources/submit-an-event/" class="btn btn-primary">Submit an event</a></p>
</div>