• 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 category 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 category from blog template

This topic is: resolved

Tagged: blog page template, exclude category, pre_get_posts

  • This topic has 6 replies, 3 voices, and was last updated 8 years, 3 months ago by Brad Dalton.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • February 13, 2017 at 11:38 am #201050
    Deluxe Designs
    Member

    I have entered the cat id I want to exclude in genesis settings and nothing happened. I also used this code to no avail:

    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_home() ) {
    		$query->set( 'cat', '-14' );
    	}
    } 

    Where 14 is the category id I do not want to display on the blog page. The category happens to be a parent category (I do not want that category nor its subcats to display) so just as a test, I tried to also exclude the subcategory id's as well and it didn't matter. I also changed the query to is_page ( 42 ) where 42 is the id of the blog page. None of these worked. This is a customized version of foodie pro that I am working on.

    http://thelittleclementine.com/blog/
    February 13, 2017 at 11:54 am #201051
    Victor Font
    Moderator

    The $query->is_home() is causing the action to fail. This function returns true only on the page you set as the “Posts page” in the WordPress settings. Change that condition to is_page('104') and it should work.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    February 13, 2017 at 12:20 pm #201053
    Deluxe Designs
    Member

    Sorry I meant to say 104 (not 42) in my original post but I have tried that as well - and just tried it again to give the benefit of the doubt - and it still did not work.

    February 13, 2017 at 12:39 pm #201058
    Deluxe Designs
    Member

    I think it is something to do with a plugin or the site. I tried the same thing on the demo site for this and it worked. I'm not sure what the difference would be.

    February 13, 2017 at 12:39 pm #201059
    Victor Font
    Moderator

    Then forget the function for now and use the built-in Genesis query_args method: https://victorfont.com/use-query_args-filter-wordpress-posts/


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    February 13, 2017 at 12:44 pm #201060
    Deluxe Designs
    Member

    That time it worked. Thank you; I hadn't seen that before.

    February 13, 2017 at 1:12 pm #201062
    Brad Dalton
    Participant

    is_home(), is_page('blog'), is_page('id') and is_page_template('page_blog.php') with pre_get_posts will not check if the Genesis page template is loaded.


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Exclude category 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

© 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