Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created October 17, 2016 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/646d496e72942b5251d484d522d762ee to your computer and use it in GitHub Desktop.
Save joshfeck/646d496e72942b5251d484d522d762ee to your computer and use it in GitHub Desktop.
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