if(class_exists("WP_FullCalendar")) {
//Remove the custom where clause before the calendar query is executed
function danbi_remove_posts_where() {
remove_filter( 'posts_where', 'wpfc_temp_filter_where' );
}
add_action('wpfc_before_wp_query', 'danbi_remove_posts_where', 10);
//Override the item timestamp
function danbi_change_item_date($item, $post) {
$start = date("Y-m-d\TH:i:s", strtotime(get_field('cal_start_date', $post->ID, false) . ' ' . get_field('start_time', $post->ID, false)));
$end = date("Y-m-d\TH:i:s", strtotime(get_field('cal_end_date', $post->ID, false) . ' ' . get_field('end_time', $post->ID, false)));
$item['start'] = $start;
$item['end'] = $end;
return $item;
}
add_filter('wpfc_ajax_post', 'danbi_change_item_date', 10, 2);
function danbi_wpfc_fullcalendar_args($args) {
$startday = str_replace('-', '', $args['scope'][0]);
$endday = str_replace('-', '', $args['scope'][1]);
unset($args['scope']);
$new_args = array(
'meta_key' => 'cal_start_date',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'cal_start_date',
'value' => array( $startday, $endday ),
'type' => 'numeric',
'compare' => 'BETWEEN',
'type' => 'DATE'
),
array(
'key' => 'cal_end_date',
'value' => array( $startday, $endday ),
'type' => 'numeric',
'compare' => 'BETWEEN',
'type' => 'DATE'
)
),
);
$args = array_merge($args, $new_args);
return $args;
}
add_filter( 'wpfc_fullcalendar_args', 'danbi_wpfc_fullcalendar_args' );
}