NB: Make sure you do a back up of your theme, files and database before attempting the tutorials

Intermediate

---- Last modified : Sep 10 2022

Estimated reading time : 0 minutes, 44 seconds - 84 words

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>