Support

Account

Home Forums ACF PRO Get Next Post Reply To: Get Next Post

  • With this code, I’m able to get the right column to post:

    <?php if( have_rows(‘tradeshows’, 40) ): ?>
    <?php
    $current_event_date = get_sub_field(‘event_date’);
    $next_event_query = new WP_Query(array(
    ‘post_type’ => ‘events’,
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => -1,
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘event_date’,
    ‘compare’ => ‘>’,
    ‘value’ => $current_event_date,
    ‘type’ => ‘CHAR’
    )
    ),
    ‘orderby’ => ‘meta_value’,
    ‘order’ => ‘ASC’
    ));

    $rows = get_field(‘tradeshows’, 40);
    ?>

    <?php if ($next_event_query->have_posts()) : while ($next_event_query->have_posts()): $next_event_query->the_post(); ?>
    <div class=”col-sm-3″>
    <h3>NEXT TRADESHOW</h3>
    <p><?php echo $current_event_date; ?></p>
    </div>
    <?php wp_reset_postdata(); ?>
    <?php endwhile; ?>
    <?php endif; ?>

    <div class=”col-sm-6 col-sm-offset-3″>
    <h3>UPCOMING TRADESHOWS</h3>
    <?php while( have_rows(‘tradeshows’, 40) ): the_row(); ?>
    <div class=”col-sm-4″>
    <p class=”eventdate”><?php the_sub_field(‘event_date’); ?><br />
    <span class=”locplace”><?php the_sub_field(‘event_location’); ?></span></p>
    </div>
    <?php endwhile; ?>
    </div>
    <?php endif; ?>

    I don’t understand how to create a ‘meta_key’ argument as you’ve mentioned since I need to retrieve the next post in the list. I’m assuming you mean this:

    $next_event_query = new WP_Query(array(
    							  'post_type'      => 'event',
    							  'post_status'    => 'publish',
    							  'posts_per_page' => -1,
    							  'meta_query'     => array(
    								array(
    								  'meta_key'   => 'event_date',
    								  'key'        => 'event_date',

    The below code posts the data in the right column within the loop that I have set:

    <p class="eventdate"><?php the_sub_field('event_date'); ?><br />
    <span class="locplace"><?php the_sub_field('event_location'); ?></span></p>

    So I’m still needing to understand how to post the next post in the left column.