Exclude Current Post

Exclude the current Post from being included in the Grid. This is useful for “Related Posts” grids.

Let’s say you have a blog, and each post from your blog also contains a grid.  And the items for this grid represent all your blog posts.  If you want to exclude the current post from this grid, you can add the following PHP snippet to your theme’s “functions.php” file.

add_filter(‘essgrid_query_caching’, ‘eg_disable_chache’, 10, 2);
add_filter(‘essgrid_get_posts’, ‘eg_mod_posts’, 10, 2);
 
function eg_mod_posts($query, $grid_id){
 
	if($grid_id == 1){
	 
		$exclude_id = get_queried_object_id();
		$query[‘post__not_in’] = array( $exclude_id );
	 
	}
	 
	return $query;
	 
}
	 
function eg_disable_chache($do_cache, $grid_id) {
	 
	if( $grid_id == 1 ) {
		return false;
	}
 
} 

In the PHP snippet, for the "grid_id == 1" parts, this will check to make sure the functionality is only applied to your specific grid.

To get the ID for your grid, visit the plugin’s main admin page where your grids are listed:

Exclude Current Post

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!