
As always, forgive my mess.
I have a client who wants to list all upcoming events on one page and previous events on another page. I have created a custom post type (event) with a repeater field (date_time) that has an ‘event_date’ and ‘time’ sub_field. I’ve managed to get things to work on my archive-event.php page, but not on a custom template page that I’m using to display previous events.
<?php
$repeater = get_field('date_time');
$today = date('Ymd');
$args = array(
'post_type' => 'event',
'posts_per_page' => -1,
'meta_key' => $repeater['event_date'],
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => $repeater['event_date'],
'compare' => '>=',
'value' => $today,
'type' => 'DATE'
),
));
global $post;
$posts = get_posts($args);
foreach( $posts as $post ) :
setup_postdata($post); ?>
<article <?php post_class('borderBottom clearfix') ?> id="post-<?php the_ID(); ?>">
<div class="col_3">
<?php if( have_rows('date_time') ): ?>
<?php while( have_rows('date_time') ): the_row();
$date = get_sub_field('event_date');
$dateFormat = DateTime::createFromFormat('Ymd', $date);
echo '<h3>' . $dateFormat->format('m/d/y') . '</h2>'; ?>
<h2><?php the_sub_field('time'); ?></h2>
<?php endwhile; ?>
<?php endif; ?>
</div>
<!--additional information that isn't affected-->
</article>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
I’ve isolated the problem to the .col_3 div, so I’ve removed the extraneous code. I suspect it has something to do with the global $post call, but I’m not sure.
Thanks.