• 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

posts in subcategories

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 › Design Tips and Tricks › posts in subcategories

This topic is: not resolved

Tagged: child categories, sub categories

  • This topic has 3 replies, 2 voices, and was last updated 5 years, 9 months ago by Brad Dalton.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • August 19, 2017 at 2:16 pm #210545
    Meg0143
    Member

    I want posts in subcategories to not also show up in parent category. Possible?

    August 19, 2017 at 5:24 pm #210548
    Brad Dalton
    Participant

    Try this code in your child themes functions file.

    add_filter( 'post_type_archive_title', 'filter_custom_post_type_archive_title', 10, 2 );
    
    function wpse_filter_child_cats( $query ) {
    
    if ( $query->is_category ) {
        $queried_object = get_queried_object();
        $child_cats = (array) get_term_children( $queried_object->term_id, 'category' );
    
        if ( ! $query->is_admin )
           
            $query->set( 'category__not_in', array_merge( $child_cats ) );
        }
    
        return $query;
    }
    add_filter( 'pre_get_posts', 'wpse_filter_child_cats' );
    

    Tutorials for StudioPress Themes & WooCommerce.

    August 19, 2017 at 6:25 pm #210549
    Meg0143
    Member

    Thanks, braddalton! Works fine!

    August 19, 2017 at 10:38 pm #210552
    Brad Dalton
    Participant

    Note : The following part was copied by mistake from another function and isn't needed.

    add_filter( 'post_type_archive_title', 'filter_custom_post_type_archive_title', 10, 2 );
    

    Tutorials for StudioPress Themes & WooCommerce.

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Design Tips and Tricks’ 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

© 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