I'm working on a WP_Query using the Modern Tribe Events Calendar
My problem is with pagination.
Is this the incorrect way to paginate the WP_Query or could there be another method for paginating the Events Calendar?
I found a tutorial that uses the WPNavi plugin but I would like use core wordpress functions.
<?php
$upcoming = new WP_Query();
$upcoming->query( array(
'post_type'=> 'tribe_events',
'eventDisplay' => 'upcoming',
'posts_per_page' => 1)
);
if ($upcoming->have_posts()) : while ($upcoming->have_posts()) : $upcoming->the_post(); ?>
<?php tribe_get_template_part( 'list/single', 'event' ) ?>
<?php endwhile;
else :
echo 'no upcoming events';
endif;
wp_reset_query();
?>
<div class="navigation"><p><?php posts_nav_link(); ?></p></div>
EDIT
This is the solution I came up with.
<?php
global $paged;
$curpage = $paged ? $paged : 1;
$upcoming = new WP_Query();
$upcoming->query( array(
'post_type'=> 'tribe_events',
'eventDisplay' => 'upcoming',
'posts_per_page' => 2,
'paged' => $paged)
);
if ($upcoming->have_posts()) : while ($upcoming->have_posts()) : $upcoming->the_post(); ?>
<?php tribe_get_template_part( 'list/single', 'event' ) ?>
<?php endwhile;
echo '<div id="navigation">';
if ($curpage != 1) {
echo '<a class="previous" href="'.get_pagenum_link(($curpage-1 > 0 ? $curpage-1 : 1)).'">‹</a>';
}
if ($curpage != $upcoming->max_num_pages) {
echo '<a class="next" href="'.get_pagenum_link(($curpage+1 <= $upcoming->max_num_pages ? $curpage+1 : $upcoming->max_num_pages)).'">›</a>';
}
echo '</div>';
endif;
wp_reset_query();
?>