Posted on

Don’t show a WordPress category on posts page

Have you ever used WordPress posts for something other than a blog post? I use them for FAQ pages, but I don’t want the FAQs to show up in the main blog, so I added this into the theme functions.php. It can also be used in a new plugin.

(?? = category id number)

function exclude_category($query) {
  if ( $query->is_home )
    $query->set('cat', '-??');
  return $query;
}
add_filter('pre_get_posts', 'exclude_category');

The minus sign in front of the category id means don’t include.