Advanced Additional Parameters

Apply advanced post queries using one of Essential Grid’s built-in plugin filters.

Careful: This article requires PHP file editing, and therefor is meant for advanced usage only.

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;
 
}
Advanced Additional Parameters

Further Resources for Web Design and Development Enthusiasts

Alright! We've embarked on quite an adventure exploring the realms of this topic. But why stop there? The world of web design and development is vast, and there's always more to learn and discover. Let's dive into some resources that'll keep your knowledge fresh, your skills sharp, and your passion ignited:

The Author

KC

Strength does not come from winning. Your struggles develop your strengths. When you go through hardships and decide not to surrender, that is strength.

Liked this Post?
Please Share it!