Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Last active July 21, 2019 22:40
Show Gist options
  • Save joshfeck/61a9e21bbc9d4111fbdf to your computer and use it in GitHub Desktop.
Save joshfeck/61a9e21bbc9d4111fbdf to your computer and use it in GitHub Desktop.
Past event archives page template for EE4. This can be adapted to most WP themes. Prints a simple unordered one page list of expired events.
<?php
// alter the query to only the primary datetimes that ended before today
// adjust query as desired
// add this to your child theme's functions.php file or into a custom plugin
function custom_posts_where_sql_for_only_expired() {
return ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end < "' . current_time( 'mysql', TRUE ) . '" ';
}
<?php
/**
Template Name: Past Events Only List
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<div class="module">
<ul class="past-event-list">
<?php
$args = array(
'limit' => 100,
'show_expired' => TRUE,
'sort' => 'DESC',
'order_by' => 'start_date',
);
add_filter( 'posts_where', 'custom_posts_where_sql_for_only_expired' );
$loop = new EventEspresso\core\domain\services\wp_queries\EventListQuery( $args );
if( $loop->have_posts() ) {
// loop through posts
while ( $loop->have_posts() ) : $loop->the_post();
?>
<li>
<a class="event-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<span class="start-date"><?php espresso_event_date(); ?></span>
</li>
<?php
endwhile;
}
remove_filter( 'posts_where', 'custom_posts_where_sql_for_only_expired' );
wp_reset_postdata();
?>
</ul>
<?php // pagination links
$big = 999999999; // need an unlikely integer
$pagination = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $loop->max_num_pages,
'show_all' => TRUE,
'end_size' => 10,
'mid_size' => 6,
'prev_next' => TRUE,
'prev_text' => '&lsaquo; PREV',
'next_text' => 'NEXT &rsaquo;',
'type' => 'plain',
'add_args' => FALSE,
'add_fragment' => ''
));
echo ! empty( $pagination ) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : '';
?>
</div><!-- #module -->
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
@davehightower
Copy link

Nice!

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