Excluding the current post from The Grid 'Related Posts'

Hi guys!

While I have just finished to customize The Grid’s skins, it appears that the basic options of this plugin don’t allow to exclude the current post from the ‘Related Posts’ grid.

Knowing that a similar solution exists for ‘Essential Grid’, would you please tell me how to adapt the PHP snippet (or another one) to my needs?

With thanks in advance,

B.

Hello @Brabant,

Thanks for asking. :slight_smile:

Unfortunately removing current post from related post in the grid plugin will require some custom development which falls outside the scope of support we can offer.

However, if you wish to use Essential Grid plugin then you can take a look at the solution shared by the plugin developer in following post.

https://www.themepunch.com/faq/exclude-current-post/

Thanks.

Hello @Prasant

Thank you for the ThemePunch link, although I can’t figure out why it could be more difficult to customize (with a pinch of PHP, CSS or else) this basic option in The Grid than in EssentialGrid

Furthermore, I have already harmonized a dozen of The Grid skins with my website design, and obviously don’t wish to start again with another plugin (nor add redundant plugins for velocity reasons).

Consequently, any simple solution would be very welcome.

Regards,

B.

Hello There,

The Grid plugin works differently with Essential grid. This plugin has its pros and cons and your issue is one of the cons. I would like to use this in your child theme’s functions.php file. Maybe we can hack the the grid’s query arguments.

function current_post_tgfilter($args){
	$args['post__not_in'] => array (get_the_ID());

	return $args;
}
add_filter('tg_wp_query_args', 'current_post_tgfilter');

We would loved to know if this has work for you. Thank you.

1 Like

@RueNel

Hello and many thanks for your good will and competences! :trophy: :blush:

The fact is except a minor ‘modification’ – caused by the syntax error, unexpected ‘=>’ (T_DOUBLE_ARROW) – the/your following code is fully effective:

function current_post_tgfilter($args) {
	
	$args['post__not_in'] = array (get_the_ID());

	return $args;

}
add_filter('tg_wp_query_args', 'current_post_tgfilter');

Best regards,

B.

Glad it’s working now and thanks for sharing :wink:

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