Skip to content

Instantly share code, notes, and snippets.

@jkudish
Created January 8, 2012 22:19
Show Gist options
  • Save jkudish/1579916 to your computer and use it in GitHub Desktop.
Save jkudish/1579916 to your computer and use it in GitHub Desktop.
<h1>Upcoming events:</h1>
<?php global $post;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$upcoming = tribe_get_events( array('eventDisplay'=>'past', 'posts_per_page'=>1,'paged' => get_query_var('page')) );
foreach($upcoming as $post) : setup_postdata($post);?>
<div class="single-event">
<div class="title"><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a> </div>
<?php endforeach; ?>
<?php if(function_exists('wp_pagenavi')) { // if PageNavi is activated ?>
<?php wp_pagenavi(); }
/**
* above is the original untouched code
* below is the better code (and it works!)
* the main difference is the use of WP_Query instead of tribe_get_events
* doing so is more efficient and ensures compatibility with WPPageNavi
* @see @link http://scribu.net/wordpress/wp-pagenavi/wpn-2-74.html for more details
*/
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$upcoming = new WP_Query();
$upcoming->query( array('post_type'=> 'tribe_events', 'eventDisplay' => 'past', 'posts_per_page' => 1, 'paged' => $paged) );
if ($upcoming->have_posts()) :
while ($upcoming->have_posts()) :
$upcoming->the_post();
?>
<div class="single-event">
<div class="title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></div>
<?php
endwhile;
wp_pagenavi( array( 'query' => $upcoming ) );
endif;
wp_reset_query();
?>
@manmar
Copy link

manmar commented Jan 9, 2012

Shouldn't it be 'eventDisplay' => 'upcoming' for upcoming events instead of 'past'?

@jkudish
Copy link
Author

jkudish commented Jan 9, 2012

Depends on what you are trying to do with it. In this case, the user wanted to display past events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment