Skip to content

Instantly share code, notes, and snippets.

@wpflames
Last active June 29, 2022 11:48
Show Gist options
  • Select an option

  • Save wpflames/176b34a51b8e1451b587ba6e276f7e8a to your computer and use it in GitHub Desktop.

Select an option

Save wpflames/176b34a51b8e1451b587ba6e276f7e8a to your computer and use it in GitHub Desktop.
ACF Query Upcoming and Past Events
<?php
$date_now = date('Y-m-d H:i:s');
$time_now = strtotime($date_now);
$args = array(
'posts_per_page' => -1,
'post_type' => 'event',
'meta_query' => array(
array(
'key' => 'date',
'compare' => $compare_operator,
'value' => array( $date_now ),
'type' => 'DATETIME'
)
),
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => 'date',
'meta_type' => 'DATETIME'
);
$the_query = new WP_Query( $args );
echo '<h2>'.$title.'</h2>';
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
event_card();
endwhile; else : ?>
<p><?php esc_html_e( 'There is no upcoming event.' ); ?></p>
<?php endif;
wp_reset_postdata(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment