Hello @dip-recipes ,
Yes, you can exclude the latest post form the Post Grid block.
Please follow this video.
I hope this helps.
Regards,
Sweta
Thread Starter
DK
(@dip-recipes)
I had tried this, but this seems to be if I want to add a grid to a post and have it exclude that particular post (the current post).
In my case, I have a static page, not a post. I want to exclude the most recent post from a specific grid. Hopefully that makes sense.
Hello @dip-recipes ,
You can exclude posts from the Post Grid block using the following filter.
To do that please follow the following steps:-
- To apply different filters for a specific block you need to add a unique class to the block from the Advanced Tab of Post Grid Block.
- You need to get the post IDs of the Pages or Posts you want to exclude.
- After that, you need to add the following filter in your child theme’s functions.php file.
function filter_post_query( $query_args, $attributes) {
// Unique class name added from Advanced tab for Post Grid.
if ( 'my-post-grid-class' == $attributes['className'] ) {
// 123 and 456 is the post id you want to exclude.
$query_args['post__not_in'] = array( 123,456 );
}
return $query_args;
}
add_filter( 'uagb_post_query_args_grid', 'filter_post_query', 10, 2 );
I hope this helps. Let me know how it goes.
Regards,
Sweta
Thread Starter
DK
(@dip-recipes)
Awesome, thank you so much!
I have the same requirement. Maybe this could be a feature of Post Grid.
-
This reply was modified 5 years, 9 months ago by
dobbylan.
Thread Starter
DK
(@dip-recipes)
Yes, I’d love to see this as an added feature.
The code above works, but I have to manually update it with the latest post ID every time I add a new post.
Hello @dip-recipes ,
I’m glad it works out for you. Thanks for letting me know.
I will surely convey your feedback to our concerned developers. I’ll put forward your thought about this to our team and if feasible we will try to improve the scenario in our future updates.
If you have any further queries, please don’t hesitate to contact us.
Regards,
Sweta