Last active
May 23, 2018 19:53
-
-
Save andrasguseo/24bf2ba3259b29e079829f112087247e to your computer and use it in GitHub Desktop.
TEC - show only the selected day on list view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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