How to have 1 category to NOT show on the mainstream (2 posts)

  1. utnalove
    Posted 3 years ago #

    Hello, all the posts that are in the categories are shown in the homepage.
    I would like to create a new category. All the posts that are only in this new category will be visible ONLY in this category (and tag pages) page, but NOT in the mainstream/homepage.

    Is it possible? How?
    Thanks much

  2. keesiemeijer
    Posted 3 years ago #

    Try excluding the category from your home page with this in your theme's functions.php:

    function my_post_queries( $query ) {
      // not an admin page and it is the main query
      if (!is_admin() && $query->is_main_query()){
          $query->set('category__not_in', array(12));
    add_action( 'pre_get_posts', 'my_post_queries' );

    Change the category id in array(12) to the category id you want to exclude.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.