Support » Developing with WordPress » Utimate category excluder not working in my website

  • Hello Building and artisan website and I will like to exclude a category in the front page. I use Ultimate category excluder but it seem not working.

    • I downloaded ultimate category excluder from plugin dashbaord section
    • activated it
    • go to setting->category excluder and select the category I wanted to hide under

      Exclude from Front Page?

    • alternatively I equally used this code below where -3 correspond to the category id I wanted to hide

      function exclude_category_home( $query ) {
          if ( $query->is_home ) {
          $query->set( 'cat', '-3' );
          }
          return $query;
          }
           
      add_filter( 'pre_get_posts', 'exclude_category_home' );
      
      ?>
    • This topic was modified 9 months, 2 weeks ago by gunkev.
Viewing 4 replies - 1 through 4 (of 4 total)
  • function exclude_category_home( $query ) {
        if ( $query->is_home ) {
        $query->set( 'category__not_in', 'category_id' );
        }
        return $query;
        }
         
    add_filter( 'pre_get_posts', 'exclude_category_home' );
    
    ?>

    what theme are you using?

    this theme might not use the default loop in the front page (posts page?) …

    please ask in your theme’s support forum.

    Moderator bcworkz

    (@bcworkz)

    Michael’s suggestion is most pertinent, but I’ve a few pedantic comments. Your code works correctly on my site (well, I used -8 for my category ID). However, “post__not_in” array form is the preferred form over “-3” string form, as Kalpesh suggests. Except you’d set 3, not 'category_id'.

    “pre_get_posts” is an action hook, not a filter. They are closely related and why either way works. Action is more correct. As an action, there’s no need to return anything. Any return is ignored by the calling code. The set() method seems to magically work despite no return value because the query object is passed by reference. Normally data is passed by value.

    bcworkz, I am saying ‘category_id’ means what they want to add that place exclude category id

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Utimate category excluder not working in my website’ is closed to new replies.