There is of course the include_children parameter for WP_Query as part of the taxonomy parameters. Which I suppose should work like this for you:
$args = array(
'tax_query' => array(
array(
'include_children' => false
),
),
);
$query = new WP_Query( $args );
Or via parse_tax_query for your category archive:
add_filter(
'parse_tax_query',
'wpse163572_do_not_include_children_in_category_archive_parse_tax_query'
);
function wpse163572_do_not_include_children_in_category_archive_parse_tax_query( $query ) {
if (
! is_admin()
&& $query->is_main_query()
&& $query->is_category()
) {
// as seen here: http://wordpress.stackexchange.com/a/140952/22534
$query->tax_query->queries[0]['include_children'] = 0;
}
}
Note: Thanks to @PieterGoosen this is now tested and confirmed working.
Related Posts:
- How to display non-hierarchical taxonomy as terms with checkboxes?
- Different template for subcategories
- Categories’ hierarchy in URL
- Categories lose hierarchy order once assigned to post
- Add Product categories to WordPress menu without losing hierarchy
- How can I get an tag to wrap each ancestor that gets outputted in this condition?
- how to get the categories for a single post in a hierarchical way
- Category tree is flattened inside admin upon saving
- Categories vs. Page Site Organization
- How to enable category hierarchy for links?
- Combining post categories and link categories?
- How to categorize posts under Category 1 and Category 2 which are separate lists of categories, and display them as separate lists in widgets
- Give a page priority over a category that has the same name?
- Add child category to parent on post creation and save
- How do I make the category sidebar widget (stock) display the total # of posts including those in subcategories?
- How to get Next/previous_post_link to go through articles in top parent category
- Hierarchical permalink structure for posts showing categories and sub-categories
- WordPress list categories dropdown with parent-child relation and child under it’s parent
- Display only subcategories of a category and not sub-subcategories
- How to load several hierarchical categories from functions.php
- Check is category parent with ids from the childs – get_term_children
- Posts not listing out sub category in hierarchy
- list all child categories that apply to current post even if those cats are empty?
- Show subChild categories
- Parent Category and Subcategory default text generated with category
- outputting taxonomy hierarchy
- Different template for subcategories
- Children categories not shown in dashboard
- Most efficient use of custom taxonomies, categories, and pages
- Display categories and their IDs
- List the category tree of all the product_cat categories
- Can I set a default featured image for a category?
- Retrieve Product category ‘NAME’ by product category ID – WooCommerce?
- Could not insert term into the database
- Activate Gutenberg in category-descriptions
- How to show subcategories in categories else show posts
- What’s the URL for a category archive?
- Weird behaviour when adding terms/term_taxonomies programmatically
- How can I get category ID by category name?
- How would I increase the Author Role to be able to add a new category?
- How to remove the parentheses from the category widget
- Filter front page posts by category
- Randomise results from a category page?
- How to get the url to tag & category base set by the user?
- Multiple level category drop-down
- How to create a category and sub-category sorted blogroll with all posts?
- Get id of category from drop down menu
- How can I only show certain posts?
- Category menu item and its last 10 posts as sub-menu
- How to create 450 categories in wp
- How to split the categories of subcategories with thumbnails
- Prevent function from triggering again when post in specific category gets another category?
- WordPress MU 2.9.2 to 3.0.5 changes to category.php
- Keep active class in post page
- Add custom category name as data-filter to switch between these categories
- Get all the blog’s categories and the related URLs?
- Why is this category page limiting the number of posts?
- What’s the difference between “parent” and “category_parent” in a WP_Term object?
- Catchable fatal error: Object of class WP_Term could not be converted to string
- Update taxonomy value of post type in query
- Is it possible to add short code and html tag in Category Description?
- Sort post’s categories by ID
- Hide tag and category boxes from the post editor
- Add multiple=”multiple” attribute to categories dropdown
- Allow dot in wordpress permalinks (only for categories)
- How to know if it’s a child taxonomy?
- Collapse subcategories in post edit screen
- Categories: A Greenhorn Question on Strategy (Not Code)
- Using a portfolio_category slug in wordpress URL
- How do I specify more than one category?
- Exclude category from Tag Template
- How to provide value for ‘selected’ on wp_dropdown_categories() for ‘multiple’ options
- Set the default category of an attachment
- exclude post from displaying in loop if it is in a category, but not in many categories
- Show Featured products in product category pages
- Need Category RSS Feed that shows all posts
- Set post categories to include parents when setting child category
- How to display post images in category view?
- Nav menu category links not showing
- Making a tourism information website [closed]
- How to remove category titles?
- How would I go about adding custom header images per category?
- Adding Categories Through Function
- Get only one of the current categories
- Show Available Taxonomy List with Current Category
- Exclude a category from the_category in the single post page
- WordPress search only showing a few posts
- Post publish directly in all categories except one need pending review
- Display category posts before others category custom query [closed]
- Get Prevous/Next Post Specific Category Without Excludes
- Pagination is not working properly in Product Category/Tag pages
- How to recreate a copy of a product category in WooCommerce? [closed]
- add_rewrite_endpoint returns 404 on archives
- Multiple category archive page
- List subcategories of active parent category (WooCommerce)
- How to display post type and category links in foreach WordPress code
- Updating category template to change how subcategories display
- Create menu / submenu from category subcategory and posts
- Sub Categories Keep Redirecting to Pages With Same Slugs
- Add multiple classes. Different style for each category tag