Skip to content

Instantly share code, notes, and snippets.

@andrasguseo
Last active May 23, 2018 19:53
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 andrasguseo/24bf2ba3259b29e079829f112087247e to your computer and use it in GitHub Desktop.
Save andrasguseo/24bf2ba3259b29e079829f112087247e to your computer and use it in GitHub Desktop.
TEC - show only the selected day on list view
<?php
/**
* Description: show only the events of the selected day in list view
*
* Usage: copy the snippet in your active (child) theme's functions.php file
*
* Plugins: The Events Calendar
* Author: Patricia Hillebrandt
* Last updated: May 23, 2018
*/
add_action( 'tribe_events_pre_get_posts', 'show_only_current_date' );
function show_only_current_date( $query ) {
$ajax_or_main = ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || $query->is_main_query();
if ( ! $ajax_or_main || empty( $_REQUEST['tribe-bar-date'] ) ) {
return;
}
if ( ! preg_match( '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $_REQUEST['tribe-bar-date'], $matches ) ) {
return;
}
$end_date = date( 'Y-m-d', strtotime( $matches[0] . ' +1 day' ) );
$query->set( 'end_date', $end_date );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment