Apply advanced post queries using one of Essential Grid's built-in plugin filters.
Careful
Using the following code snippet, you can modify the post query used for your grid's post source.

// code can be added to your themes functions.php file
add_filter('essgrid_query_caching', 'eg_stop_caching', 10, 2);
add_filter('essgrid_get_posts', 'eg_mod_query', 10, 2);
// turn off caching for your grid
function eg_stop_caching($do_cache, $grid_id) {
if($grid_id == YOUR_GRID_ID) return false;
return true;
}
function eg_mod_query($query, $grid_id){
if($grid_id == YOUR_GRID_ID) {
//modify $query to your likings
}
return $query;
}
In the following example, where posts represent “events” that have a start and end date, we could use the filter to only show events from the past, or even better, only show events that are scheduled to happen in the future.
// code can be added to your themes functions.php file
add_filter('essgrid_query_caching', 'eg_stop_caching', 10, 2);
add_filter('essgrid_get_posts', 'eg_mod_query', 10, 2);
// turn off caching for your grid
function eg_stop_caching($do_cache, $grid_id) {
if($grid_id == YOUR_GRID_ID) return false;
return true;
}
function eg_mod_query($query, $grid_id){
// show only upcoming events in the future
if($grid_id == 36){
$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'] = '>=';
}
// show only events from the past
if($grid_id == 50){
$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;
}