Home › Forums › Support › How to hide some posts from blog page This topic has 7 replies, 2 voices, and was last updated 3 years, 3 months ago by David. Viewing 8 posts - 1 through 8 (of 8 total) Author Posts January 3, 2021 at 6:58 am #1603776 Matteo I’d like to create a new posts category and hide those posts (the entire category) on the blog page. The posts will exist and they will be in the sitemap index, but they should be invisible to readers. How can I do? January 3, 2021 at 7:27 am #1603826 DavidStaff Customer Support Hi there, you can use this PHP Snippet to exclude a category: add_action( 'pre_get_posts', function( $query ) { if ( !is_admin() && $query->is_main_query() ) { $query->set( 'cat', -10 ); } } ); the 10 value is the Category ID. You can get the ID by editing the Category and checking the URL. January 18, 2021 at 7:27 am #1623707 Matteo This code hide also the post from Posts-All Posts in WP dashboard and I can’t find the post. January 18, 2021 at 7:57 am #1623760 DavidStaff Customer Support Updated the code above to fix that. January 18, 2021 at 7:58 am #1623764 Matteo Resolved with this code: function exclude_category_home( $query ) { if ( $query->is_home ) { $query->set( 'cat', '-55' ); } return $query; } add_filter( 'pre_get_posts', 'exclude_category_home' ); Where 55 is a random category number to change. January 18, 2021 at 8:01 am #1623769 DavidStaff Customer Support Glad to hear you found the answer January 18, 2021 at 8:01 am #1623770 Matteo Also your code works. Thanks. January 18, 2021 at 8:05 am #1623780 DavidStaff Customer Support You’re welcome Author Posts Viewing 8 posts - 1 through 8 (of 8 total) You must be logged in to reply to this topic. Log In Username: Password: Keep me signed in Log In