Aller au contenu
FR

Excluding a Category from Archives

Version audio de cet article

What’s my category’s ID?

In order to get your category’s ID, simply go in the Category section. Click on the Category in question and the ID will be displayed in the URL as such:

Exclure une catégorie des archives / Front Page WordPress

Here’s the function we’ve used with the pre_get_posts filter.

add_action('pre_get_posts', 'remove_themespress_post_categories' );
function remove_themespress_post_categories( $wp_query ) {
  // 31 = ID de ma catégorie
  $remove_cat = '-31';
  // supprimer des archives feeds, search, and home page, mais pas admin ou category
  if( (is_home() || ( is_archive() && !is_category() && !is_tag() )) && !is_admin()) {
    set_query_var('cat', $remove_cat);
  }
}

We could also used this option via a Query Post. Here are a few examples of Query Posts.