Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jonahcoyote/161371a725a9301dcdebf2c43985b094 to your computer and use it in GitHub Desktop.
Save jonahcoyote/161371a725a9301dcdebf2c43985b094 to your computer and use it in GitHub Desktop.
The Events Calendar - Target a Specific Event List Widget to Only Show Todays Events
/**
* The Events Calendar - Target a Specific Event List Widget to Only Show Todays Events
*
* modify tribe-events-adv-list-widget-2 to id of widget
*/
function tribe_modify_list_widget_args_for_today( $args ) {
$start_date_init = date ( 'Y-m-d' );
$start_date_end = $start_date_init . ' 23:59:59';
$args['meta_query'][] = array('key' => '_EventStartDate','type' => 'DATETIME','compare' => '>=','value' => $start_date_init);
$args['meta_query'][] = array('key' => '_EventStartDate','type' => 'DATETIME','compare' => '<=','value' => $start_date_end);
return $args;
}
add_filter( 'widget_display_callback', 'tribe_target_specific_widget', 10, 2 );
function tribe_target_specific_widget( array $instance, $widget ) {
remove_filter( 'tribe_events_list_widget_query_args', 'tribe_modify_list_widget_args_for_today', 10, 1 );
if ( is_a( $widget, 'Tribe__Events__Pro__Advanced_List_Widget' ) && $widget->id == 'tribe-events-adv-list-widget-2' ) {
add_filter( 'tribe_events_list_widget_query_args', 'tribe_modify_list_widget_args_for_today', 10, 1 );
}
return $instance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment