I am using Events Manager to control my Events, but Essential Grids to display previews of these events in various places throughout my site. An example of this is http://staging-dbmax.transitiongraphics.co.uk/events/.
Essentially I am trying to get Essential Grids to recognise the Date Field of the event and sort the grid accordingly. Whilst hiding events that are in the past.
Thus far through research I have managed to isolate the grids and pull in the date, whilst hiding older events. However it doesn't quite work. Some of the events do not place correctly in the grid.
To achieve what I have so far I did the following:
Added parameters field under source tab of Essential Grids:
( 'meta_query' => array( array( 'meta_key' => '_event_start_date' , 'meta_value' => $today, 'compare' => '>=' , 'type' => 'date')) , 'orderby' => 'meta_value' , ) ); ?>
Added the following to my Functions PHP file:
add_filter('essgrid_query_caching', 'eg_disable_caching', 10, 2);
function eg_disable_caching($do_cache, $grid_id){ //disable caching for the particular grid
if($grid_id == 43 || $grid_id == 48 || $grid_id == 50){ //replace 1 with your desired grid id
return false;
}
return true;
}
add_filter('essgrid_get_posts', 'eg_modify_query', 10, 2);
function eg_modify_query($query, $grid_id){
if($grid_id == 43 || $grid_id == 48){ //replace 1 with your desired grid id
$query['meta_query'] = array( 'key' => '_start_ts', 'value' => current_time('timestamp'), 'compare' => '>=', 'type'=>'numeric' );
$query['meta_key'] = '_start_ts';
$query['meta_value'] = current_time('timestamp');
$query['meta_value_num'] = current_time('timestamp');
$query['meta_compare'] = '>=';
}
if($grid_id == 50){ //replace 1 with your desired grid id
$query['meta_query'] = array( 'key' => '_start_ts', 'value' => current_time('timestamp'), 'compare' => '<=', 'type'=>'numeric' );
$query['meta_key'] = '_start_ts';
$query['meta_value'] = current_time('timestamp');
$query['meta_value_num'] = current_time('timestamp');
$query['meta_compare'] = '<=';
}
return $query;
}
And finally, this HTML goes in the skin of the Grid to pull the date in from Events Manager:
[event post_id="%post_id%"]#_EVENTDATES[/event]
Obvously if anyone has a better solution, I'd be happy to use that instead, otherwise, there something in the above which is not sorting correctly?