Archived topic
Exclude category from loop
21 replies · Started by lock-e73 on May 30, 2015
The generatepress related posts that appear under posts; I think it's sorted by recency.
Can you raise a new topic where you can share a link to your site and ill take a look at whats required.
I created a new Hook called Hide Uncategorized Posts in Blogroll. Uncategorized category ID=1. It has the following code:
<?php
add_filter('pre_get_posts', 'excludeCat');
function excludeCat($query) {
if ( $query->is_home ) {
$query->set('cat', '-1');
}
return $query;
}
?>
The hook is set to generate_before_header and Execute PHP is checked. The location is set to Blog.
I have a blog called Summer Camps Dublin OH that has the Uncategorized category in it, and it still shows in the Blogroll. Any ideas what I'm missing?
That code should be added using one of these methods:
Adding PHP: https://docs.generatepress.com/article/adding-php/
And can you make sure Uncategorized has ID of 1?
Thanks Leo. I reconfirmed the ID was in fact 1. I downloaded and used Code Snippet for the PHP and it worked. I appreciate your help!
No problem :)