I currently have a query for an "Event" category that looks for the ACF event_date field.
Can I use the ACF Repeater option to add multiple event dates to a single post, and then update the query so that it will repeat the same post with multiple event dates in the loop multiple times in order based on the event dates associated with post?
Will that work, repeat a post in the loop using the ACF repeater for multiple event dates?
Current Query with single event_date field.
<?php
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'events'
)
),
'meta_query' => array(
array(
'key' => 'event_date',
'value' => date("Y-m-d"),
'compare' => '>',
),
),
'posts_per_page' => 5,
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'meta_type' => 'NUMERIC',
'order' => 'ASC'
);
$query = new WP_Query( $args );
?>
<?php if ( $query->have_posts() ) : ?>
<!-- the loop -->
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<?php
$date = null;
if( get_field("event_date") ){
$date = date_format( date_create( get_field("event_date") ), "F j, Y" );
}
?>
<div class="program-event-wrapper">
<?php if( $date): ?>
<h5><?php echo $date; ?></h5>
<?php endif; ?>
<p>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</p>
</div>
<?php endwhile; ?>
<!-- end of the loop -->
<?php //wp_reset_postdata(); ?>
<?php endif; ?>