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?
- Get the children of the parent category
- Display All Products by Category with WooCommerce
- Retrieve Product category ‘NAME’ by product category ID – WooCommerce?
- Woocommerce get category image full size
- Should category.php and The Loop be used if the query needs to be customizable?
- Exclude the category from the WordPress loop
- How do I get the category URL from get_the_category?
- get_field not displaying my custom field value
- Default WP Gallery – show only galleries of a certain category
- Rearranging posts based on categories
- WP_Query not looking at child category
- Randomise results from a category page?
- Get page content by category or tag
- Programmatically create product category and add thumbnail in woocommerce
- Display all posts in category, with specific tag posts at top
- Show div only if post is in specific category
- Reflect nested categories in appearance > menus
- Create product category and keyword search form in woocommerce? [closed]
- How to show a category post to a specific registered user
- Display list of Sub-Categories and the posts they contain, within one main Category
- Category page showing posts from all categories
- How can I create a loop to build slides based on multiple categories using Coda Slider
- Create a full width responsive header image per page
- Get a list of commas separated categories inside a loop
- Using same slug name for a page and category
- How do I edit pre_get_post for the category the user is currently in?
- Categories list loop – add separator every year
- How would you create a “weekly” archive?
- Remove “Category Archives: title” at the top of a category page [duplicate]
- How to exclude categories from recent posts, recent comments & category widgets?
- How to have a static category/author page?
- I use same slug name for category and page
- Display WooCommerce product categories in a 4 columns custom menu [closed]
- Page with the same name of a category
- Display one latest post from multiple categories
- How to select product category while adding new product in woocommerce? [closed]
- Use get_term_children to get the sub category of a parent category for the current post
- Hide uncategorized products from the shop page
- How do I get the total number of categories in a list of search results?
- Check if post belongs to any category
- Remove word “Category” from WooCommerce product page [closed]
- Show posts of category in a page
- Filtering search results
- WooCommerce change category url and product base
- How do I display the posts from a custom post type on a category.php page?
- Show pages and articles in category search result
- How to group the loop posts in a particular by author?
- How to create taxonomy values for pages and list them in wp-admin
- Display products for a category, sorted by post_excerpt
- What type of page should i use? static page or category page? and what’s the difference? [closed]
- Output link to category from WP_Query loop of woocommerce products
- display woocommerce all category title on home page
- Exclude category from loop not working
- Listing Parent, Child and GrandChild Categories and then the PostTitles on Page Template !
- Add Icons to the Product Category Sidebar Widget WooCommerce
- Duplicate Category and Page URL loads Category instead of the Page
- Add Product categories to WordPress menu without losing hierarchy
- 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
- Display “add to cart” button on every listing in product category page?
- How to get product count with respect to categories in WooComerce
- If newest post of category is newest post in general, skip first post of category
- Custom page for WooCommerce’s /product-category/
- a-z list, categories and sub categories in loop
- Getting categories id for all products in cart
- Get woocommerce catogry
- Viewing category pages without the word ‘category’ in URL
- in_category() works in single.php but not in page.php?
- Why would in_category only return one post in a specific category?
- get_cat_ID() not wokring
- Is it possible to select and edit the way the most recent post from a certain category is displayed on the page?
- Categories vs. Page Site Organization
- Display child categories in WooCommerce
- WooCommerce duplicate sub categories and product slugs
- How do I automatically put categories and their descriptions on a WP Page?
- Set post categories to include parents when setting child category
- Displaying multiple loops based off of category
- WooCommerce IF statements not working
- Linking products to categories
- Woocommerce category show subcategories only/omit posts for specific category
- Warning: sizeof (): Parameter must be an array or an object that implements Countable, On products pages
- How to loop only categories without posts (+ show category featured image with acf) [closed]
- Omit specific product categories from WooCommerce shortcode
- products nested by subcategories in a current category archive
- Additional featured post on first page
- WC 3.x Get categories from variable product of the cart
- editing fonts of category links from the_category() funtion