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
- Is There a Difference Between Taxonomies and Categories?
- WooCommerce: List All Categories
- How can I hide a category from Contributors in the edit/add new post screen?
- Wrap Post count in a span
- wp_nav_menu not appearing for a couple pages
- Trash bin for categories
- Sticky Posts Not Sticking to Top of Category Archive
- How to exclude categories from recent posts, recent comments & category widgets?
- Exporting just posts of a specific category
- hide specific categories from showing
- Category Search functionality on category metabox (wordpress admin)
- How to get category id in single.php wordpress?
- how do I filter single_cat_title to remove all instances of a particlular word
- If a post has two categories with different permissions, what will happen? [closed]
- Dropdown category filter
- Category page shows Oops! That page can’t be found
- How to find the number of Tags a post has?
- How can I enable a TINYMCE rich text editor in the admin interface?
- Add title, post content, and category like add_post_meta and update_post_meta
- How to create button to direct to certain category
- Highlight wp_nav_menu when category is selected
- query order by category
- How to make 2 tag feeds show up on 1 page?
- Best way of getting WooCommerce category path
- Display the last post by each category?
- Order categories by name or view count
- How to assign posts without any category to the default category
- Filter $cpt categories to omit certain category
- How to rewrite the post URL according to the category?
- ajax for filtering posts by category in wordpress loops
- Create category post shortcode
- Question on using custom structures for categories
- Wrong category nice name is displayed on archive page
- Tags Instead of Category
- Cannot filter categories by parent category
- Redirect year month day postname permalink structure to category postname structure
- Show all sub categories?
- Generating a feed of all but one category of posts
- Displaying another main nav menu for specific category
- How to display the 5 latest post titles but allow only 1 in there of a specific category
- How to add categories using mysql
- Posts made to category don’t show up (do show up on frontpage)
- Display all categories but only if they have posts in them that have a specific tag assigned
- How to fix select filter on category
- wp_dropdown_categories() works correctly but the list is not filtered in admin for custom post type. What is the problem?
- Add $args to wp_list_categories
- Show audio player only in specific post type category
- Check with Jquery if second level checkbox from categories are checked
- Regarding Tags And Categories
- How to show entries related to main category
- selecting categories that have products with tag/category
- How to get WooCommerce Product Categories and its children’s children?
- Media Library Category Exclude Tree
- When category name and title are the same … WP will select archive.php instead of single.php
- Re-coding category-template.php to go to custom URL
- Category removal – Portfolio Category:
- How to display child-category PAGES on a category page
- How get all media from a posts category by db?
- Cant get unique_array() work on get_the_category() foreach loop
- Show One Level Category id
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- how to Specifies an author / editor to edit one category only?
- Formating content in category.php
- How to use Greek characters/letters in a query?
- Getting categories to change appropriately when using $cat = ‘ ‘;
- Display post content from category name using ajax
- How to display the category featured images [closed]
- Echo Category In Loop
- Function to reference post meta in place of category Woocommerce