Only active Events - Extensions for The Events Calendar plugin by Modern Tribe
<?php | |
/** | |
* Only active Events | |
* | |
* Extensions for The Events Calendar plugin by Modern Tribe | |
* | |
* @namespace ECE - The Events Calendar Extensions | |
*/ | |
/** | |
* Add a checkbox to the extensions panel | |
*/ | |
function ece_add_extensions_panel( $widget, $instance ) { | |
$instance = wp_parse_args( ( array ) $instance, array( | |
'only_active_events' => '' | |
) ); | |
$only_active_events = $instance['only_active_events']; | |
echo '<p>'. | |
'<label for="'.$widget->get_field_id('only_active_events').'">'. | |
'<input type="checkbox" class="checkbox" id="'.$widget->get_field_id('only_active_events').'" name="'.$widget->get_field_name('only_active_events').'" '; | |
echo checked( (bool) $instance["only_active_events"], true ).' />'; | |
echo _e( 'Use "Only active events" filter extention','categorypostspro' ). | |
'</label>'. | |
'</p>'; | |
} | |
add_filter('cpwp_bottom_mysettings_panel','ece_add_extensions_panel', 10, 2); | |
/** | |
* Filter only active Events | |
*/ | |
function ece_get_active_events ( $query, $widget, $instance ) { | |
if(isset($instance['only_active_events'])&&$instance['only_active_events']) { | |
$attr = $query['meta_query']; | |
$query = array_merge( $query, array( 'meta_query' => array( | |
'relation' => 'AND', | |
array( | |
'key' => '_EventEndDate', | |
'value' => date( 'Y-m-d' ), | |
'compare' => '>=', | |
'type' => 'DATETIME' | |
), | |
$attr | |
) | |
) | |
); | |
$query = array_merge( $query, array( | |
'order' => 'ASC' | |
) | |
); | |
} | |
return $query; | |
} | |
add_filter( 'cpwp_query_args', 'ece_get_active_events', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment