• 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

Exclude categories from blog template

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 › Exclude categories from blog template

This topic is: resolved

Tagged: Course Maker Pro, exclude category

  • This topic has 6 replies, 3 voices, and was last updated 3 years, 2 months ago by Colinz.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • November 18, 2019 at 10:38 am #494820
    Colinz
    Participant

    Hi,

    I thought that there was a simple solution, but now the dedicated Genesis setttings page has gone I am unable to remove defined 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:

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

    Sadly neither work.

    can anyone here direct me to a working solution please?

    Cheers
    Colinz

    http://109.199.117.248/~thecollectivescc
    November 18, 2019 at 2:57 pm #494822
    Terry
    Member

    Hi,

    Try (this example uses category ids 30 & 29)

    function exclude_category_blog( $query ) {
       if ( $query->is_home ) {
          $query->set( 'cat', '-30' ); //multiple categories replace '-30' with '-30 -29' to exclude categories 29 & 30 
       }
       return $query;
    }
     
    add_filter( 'pre_get_posts', 'exclude_category_blog' );

    Hope this helps.

    November 18, 2019 at 3:36 pm #494824
    Terry
    Member

    Sorry, try this...

    <script src="https://gist.github.com/maroon-tlc/da29a24d22ce827a29072852d92714b0.js"></script>

    November 18, 2019 at 3:46 pm #494826
    Terry
    Member

    here

    Sorry, such a Monday :/

    November 18, 2019 at 8:57 pm #494839
    Anita
    Keymaster
    // 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', '-5,-7' );
    	}
    }

    Try that and see if it works (replace -5 and -7 with your cat id's).

    **The code was updated**


    Love coffee, chocolate and my Bella!

    November 19, 2019 at 4:05 am #494848
    Colinz
    Participant

    Hi Anita,

    Thanks for the code, worked like a treat.

    November 19, 2019 at 4:07 am #494849
    Colinz
    Participant

    Thanks for your help Terry.

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Exclude categories from blog template’ is closed to new replies.

CTA

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

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 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