Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Exclude active events from Event Espresso event lists (only show upcoming events). You can add this to a functions or into your WordPress theme's functions.php file.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
add_action( 'pre_get_posts', 'my_custom_ee_posts_where_hook' );
function my_custom_ee_posts_where_hook ( $query ) {
if (
isset( $query->query_vars['post_type'] ) &&
( $query->query_vars['post_type'] == 'espresso_events' ||
( is_array( $query->query_vars['post_type'] ) &&
in_array( 'espresso_events', $query->query_vars['post_type'] ) ) ) &&
! $query->is_singular )
{
add_filter( 'posts_where', 'my_custom_ee_posts_where' );
}
}
function my_custom_ee_posts_where( $SQL ) {
$SQL .= ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start > "' . current_time( 'mysql', true ) . '" ';
return $SQL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment