you want to display only parent category products and remove the child category products. Add the following lines of code at the end of your theme’s functions.php file.
function exclude_product_cat_children( $wp_query ) {
if ( isset( $wp_query->query_vars['product_cat'] ) && $wp_query->is_main_query() ) {
$wp_query->set(
'tax_query', array( array (
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $wp_query->query_vars['product_cat'],
'include_children' => false
) )
);
}
}
add_filter('pre_get_posts', 'exclude_product_cat_children');
Related Posts:
- How to check if I’m on the last page of posts?
- Loop with Dynamic Categories
- Listing all posts from current category on page
- Remove product category placeholder image (Woocomerce)
- WooCommerce – How to show specific category first-rest of products-specific category last
- How to insert category list into post creation page, and retrieve chosen categories?
- Display single category name in woocommerce loop
- Do not show sub categories in the loop on archive-product.php
- Remove any product that is featured from regular display loop [WooCommerce]
- Two Sections on Woocommerce Catergory Page [closed]
- Getting the Most Recent Posts from Multiple Categories
- Template category.php with page (no posts)
- How to distinguish pages created by woocommerce?
- Programmatically create product category and add thumbnail in woocommerce
- Create product category and keyword search form in woocommerce? [closed]
- How can I create a loop to build slides based on multiple categories using Coda Slider
- How do I edit pre_get_post for the category the user is currently in?
- Remove “Category Archives: title” at the top of a category page [duplicate]
- How to exclude categories from recent posts, recent comments & category widgets?
- Duplicate Category and Page URL loads Category instead of the Page
- Category archive page – loop through posts of certain tag (with pagination) – pre_get_posts
- Add a specific category at a specific place to the menu that uses wp_list_pages
- If newest post of category is newest post in general, skip first post of category
- Why would in_category only return one post in a specific category?
- WC 3.x Get categories from variable product of the cart
- editing fonts of category links from the_category() funtion
- How to make 2 tag feeds show up on 1 page?
- Taxonomy name repeating when showing 2 posts from each category
- Search in custom post type AND in pages with category
- Best way of getting WooCommerce category path
- Display the last post by each category?
- Give a page priority over a category that has the same name?
- Multiple Loops on category.php with pagination on last loop
- How to exclude the last post from a category(featured for example) from the main loop?
- Different banner for different section
- How can you change the permalink for pages?
- ajax for filtering posts by category in wordpress loops
- Should I use “Categories ” or “Pages” for a WordPress Static Site (A non blog site)?
- Limit get_categories to show each category once
- Building Menu from Woocommerce Product Categories
- woocommerce related products by specific categories [closed]
- Show Posts from Single Category Not Working
- Is there a reason I cannot get the current category in a loop?
- new WP_Query all post in a category inside the loop
- Problem with different query loops (and “main loop”) on category template page!
- How to do paging in the loop?
- How to add orderby parameter for sorting on category.php
- How do I get category and page ID’s?
- How to loop custom post_type from (a) specific category(ies)?
- List just subcategory and products of active category page in Woocommerce
- Category tags with comma’s
- Display posts of certain categories to specific user roles
- Trying to create a Categorised Index (archive?) to use as my Home Page
- Template for product-category page [closed]
- Category nicename inside loop in wordpress
- filter a loop base on specific category
- Problem with multiple loops in wordpress theme
- custom query for both category and pages using global $wpdb;
- Editing Loop So It Targets Specific Tags?
- posts going to 2 pages/categories only show up in 1
- Posts made to category don’t show up (do show up on frontpage)
- displaying the last product comment in the woocommerce category
- How to use category slug with a regular page
- Display all categories but only if they have posts in them that have a specific tag assigned
- Woocommerce only display child category when parent is checked (on add new product page)
- Show audio player only in specific post type category
- How to prevent WordPress from redirecting single page to prefixed category archive with same name?
- In if…else condition, the else statement shows even if if statement is correct
- How can I display all products from all categories on one page with woocommerce?
- How to edit woocommerce sub-category page
- selecting categories that have products with tag/category
- Restrict retrieved terms by category?
- Please tell how to stop the category from showing up on posts
- Woocommerce Category Sort Dropdown
- Woocommerce: all products of all categories instead products of one category
- Loop by category and meta_key
- How to get WooCommerce Product Categories and its children’s children?
- Woocommerce change tag_id to name
- Assign a class to first element in category in loop
- Need help to structure our a complex hierarchy
- Category page shows only 1 post when that post has more than 1 category?
- Configure query with multiple categories in a custom order?
- How can I modify this code to iterate over an array of categories?
- Paginations in Category Page Leads to Sample Pages
- How to exclude a specific categogy from a custom page template
- Category menu that filters out empty categories
- WordPress Numeric Pagination with Query String [duplicate]
- My Query is getting the wrong data
- Need help with category page customization meeting certain condition
- How do i add custom post types to this query?
- Custom WordPress category page showing all posts rather than the specified category
- Do not show all post from all categories, just show posts from category in current loop
- WooCommerce category display in custom page
- Woocommerce custom taxonomy order
- Echo Category In Loop
- Update wordpress menu with woocommerce products
- Get all categories
- Function to reference post meta in place of category Woocommerce
- Get categories by title descendant
- Add custom fields to Woocommerce Category Page