Add Previous / Next Post Links to Custom Events Calendar Query

I used this on a custom page template showing only Past Events.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
	'post_type' => 'tribe_events',
	'posts_per_page' => 12,
	'meta_query' => array(array(
        'key' => '_EventEndDate',
        'value' => current_time( 'Y-m-d' ),
        'compare' => '<'
    )),
    'paged' => $paged
);
$event = new WP_Query($args);
if ($event->have_posts()) : while($event->have_posts()) : $event->the_post(); 
    
    // repeating content
						
endwhile; ?>

<div class="navigation">
	<div class="nav-previous alignleft"><?php  echo get_next_posts_link( 'Older', $event->max_num_pages ); ?></div>
	<div class="nav-next alignright"><?php echo get_previous_posts_link( 'Newer' ); ?></div>
</div>

<?php else : ?>
	<p><?php _e('Sorry, no events matched your criteria.'); ?></p>
<?php endif; ?>

Source.

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.