• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Removing blog categories from Blog page

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Removing blog categories from Blog page

This topic is: not resolved

Tagged: blog page, blog template

  • This topic has 8 replies, 3 voices, and was last updated 5 years, 6 months ago by Terry.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • November 19, 2019 at 6:44 am #494858
    Colinz
    Participant

    Hi,

    I'm having issues excluding blogs with specific categories from the blog page.

    I have tried:

    add_action( 'pre_get_posts', 'be_exclude_category_from_blog' );
    /**
    * Exclude Category from Blog
    *
    * @author Bill Erickson
    * @link http://www.billerickson.net/customize-the-wordpress-query/
    * @param object $query data
    *
    */
    function be_exclude_category_from_blog( $query ) {

    if( $query->is_main_query() && $query->is_page('9') ) {
    $query->set( 'cat', '-50','-61','-62' );
    }
    }

    and I have tried (on the blog page):

    Custom Field:
    Name: query_args Value: cat=-50,-61,-62

    A moderator suggested:
    // Exclude categories from blog archive.
    add_action( 'pre_get_posts', 'exclude_categories_blog_archive' );
    function exclude_categories_blog_archive( $query ) {
    if( $query->is_main_query() ) {
    $query->set( 'cat', '-61,-62,-50' );
    }
    }

    But that removes them from the Posts> All Posts as well as the blog page.

    Help gratefully received.

    Colinz

    November 19, 2019 at 1:44 pm #494871
    Terry
    Member

    Right, the $query->is_main_query() filters those specified categories from the main query which is what you're displaying on the posts page (Blog).

    It looks like you have a number of post listings on your site.
    Are you trying to filter ob the blog and other locations? Add a test for that page:
    `// Exclude categories from blog archive.
    add_action( 'pre_get_posts', 'exclude_categories_blog_archive' );
    function exclude_categories_blog_archive( $query ) {
    if ( ! is_admin() && $query->is_main_query() && $query->is_home() ) {
    $query->set( 'cat', '-61,-62,-50' );
    }elseif ( is_page(whatever_the_page_id)) {
    // for single category 5
    $query->set( 'cat', ‘-5’ );

    // for multiple categories 3 & 4
    //$query->set( 'cat', '-3, -4' );
    }`

    November 19, 2019 at 1:52 pm #494874
    Terry
    Member

    The ! is_admin() && tests for admin to distinguish main query.

    November 19, 2019 at 2:01 pm #494875
    Terry
    Member

    Lastly, you don't need both conditions but it helps me for understandability/readability
    $query->is_main_query() && $query->is_home()

    November 20, 2019 at 5:59 am #494895
    Brad Dalton
    Participant

    Another method is to use custom fields like this

    You can also use the genesis_pre_get_option_blog_cat filter hook.


    Tutorials for StudioPress Themes.

    November 20, 2019 at 7:32 am #494899
    Colinz
    Participant

    Thank you both for taking the time to help me out. I now have it set up as I wanted.

    November 20, 2019 at 9:18 am #494901
    Terry
    Member

    @braddalton To share my head banging the other day... I'm possibly not using the query_args correctly but now (WP 5.3, Genesis 3.2.1, Genesis Sample 3.2.1) the custom fields approach works for a page that is populated with posts (say with AB Posts and Pages Grid block) but not on a page titled "Blog" that is set as Posts Page.

    Tried both query_args 'cat=-5'(no quotes in field) as well as 'category__not_in'(no quotes in field) on the Blog page, neither successful. However, action hook (as above) was successful.

    November 20, 2019 at 9:29 am #494902
    Brad Dalton
    Participant

    Don't set it as posts page.


    Tutorials for StudioPress Themes.

    November 20, 2019 at 10:15 am #494903
    Terry
    Member

    Thanks Brad! 🙂

  • Author
    Posts
Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble