[Resolved] Exclude category from loop

Home Forums Support [Resolved] Exclude category from loop

Home Forums Support Exclude category from loop

Viewing 7 posts - 16 through 22 (of 22 total)
  • Author
    Posts
  • #1445593
    Olaniyi

    The generatepress related posts that appear under posts; I think it’s sorted by recency.

    #1445671
    David
    Staff
    Customer Support

    Can you raise a new topic where you can share a link to your site and ill take a look at whats required.

    #1445942
    Olaniyi
    #1457227
    Toby

    I created a new Hook called Hide Uncategorized Posts in Blogroll. Uncategorized category ID=1. It has the following code:

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

    The hook is set to generate_before_header and Execute PHP is checked. The location is set to Blog.

    I have a blog called Summer Camps Dublin OH that has the Uncategorized category in it, and it still shows in the Blogroll. Any ideas what I’m missing?

    https://www.classroomantics.com/blog/

    #1457250
    Leo
    Staff
    Customer Support

    That code should be added using one of these methods:
    Adding PHP: https://docs.generatepress.com/article/adding-php/

    And can you make sure Uncategorized has ID of 1?

    #1457281
    Toby

    Thanks Leo. I reconfirmed the ID was in fact 1. I downloaded and used Code Snippet for the PHP and it worked. I appreciate your help!

    #1457292
    Leo
    Staff
    Customer Support

    No problem 🙂

Viewing 7 posts - 16 through 22 (of 22 total)
  • The topic ‘Exclude category from loop’ is closed to new replies.