Archived topic
Exclude categories from blog page only
3 replies · Started by Incal on July 4, 2022
Hi,
I'm trying to exclude some categories from the blog page using the code on this page: https://docs.generatepress.com/article/exclude-categories-from-posts-page/
However, this excludes the categories from any loops (including GP loop block and Facetwp).
Is there a way to limit the exclusion to the blog page only?
Thank you,
Kevin
Hi Kevin,
The code should exclude the category from the blog page loop, it won't affect the other archive page's loop.
But GB loop uses the blog loop by default if there is no other parameter set.
You can try modify the PHP code to this:
add_filter('pre_get_posts', 'excludeCat');
function excludeCat($query) {
if ( $query->is_home && is_home()) {
$query->set('cat', '-3,-5,-23');
}
return $query;
}
Hi Ying,
That's exactly what I was looking for!
Thank you once again for your help.
Kevin
You are welcome Kevin :)