Exclude the current port in related grid

Hi,

I am working on portfolio website where I want related projects to show on each portfolio page. I achieved that by creating essential grids with selected categories. Now, I want to exclude the current post from that related post list. I searched for the code online and did that. It works perfectly for single grid but I want to do that for multiple grids as there may be different categories.

I added the following code in functions.php


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 == 2){

		$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 == 2) {
		return false;
	}

}

How do i change the code to include multiple grid ids in this code … if( $grid_id == 2)

Regards,
Amit

Hello Amit,

Thanks for writing in!

To include multiple grid, you will need to add a condition:

if( $grid_id == 1 || $grid_id == 2 || $grid_id == 3)

For more details, you can refer to this links:

Thanks! You are Awesome :grinning:

You’re welcome, Bamidele. Amit. Glad we’re able to help.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.