Archived topic
hidden category page Blog
5 replies · Started by alexis on December 2, 2019
Hi..,
Sorry I didn't find an answer to my problem:
I want certain categories (e. g. projects) not to appear on the blog page.
I used this function incorrectly:
add_filter('pre_get_posts', 'excludeCat');
function excludeCat($query) {
if ( $query->is_blog ) {
$query->set('cat', 'projets');
}
return $query;
}
Which php code to include please ?
Hi there,
Tom provides the code here:
https://generatepress.com/forums/topic/exclude-category-from-loop/#post-111543
Yes, but it doesn't work. By which I replace "is_home" as I am the blog page?. And the'3, 5 and 23' I replaced them with the project categories (name of my category of articles)
You can see the top level conditional tags here:
https://docs.generatepress.com/article/using-hooks-conditional-tags/#blog-posts-page
is_home is the Blog Page not to be confused with the is_front_page which is the home page.
The query must use the ID of the category - not its slug.
Edit the category you wish to exclude and inspect the URL within you will see eg. ID=4
The exclude query will then look like:
$query->set('cat', '-4');
Note the - must remain as this is what removes the category.
Thank you very much! Sorry I was missing some elements but with these explanations I understand. It works well. This is my first site with this theme which is very good for customization
I must say that WP's naming conventions can scramble the brains a little. Glad to be of help and happy to hear your liking GPP