Skip to content

Instantly share code, notes, and snippets.

@jesseeproductions
Created January 27, 2016 15:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jesseeproductions/a99528506ec2f42c8e3f to your computer and use it in GitHub Desktop.
Save jesseeproductions/a99528506ec2f42c8e3f 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