The easiest way to do this would be to use wp_list_categories
instead. It has depth
parameter which will do exactly what you want (you can use custom walker class, if you need different output than default one).
Another way would be to write your own code (but it won’t be a beautiful one). You can use something like this:
$args = ...
$categories = get_categories( $args ); // $category_ID as child_of
foreach ($categories as $k=>$category) {
if ( $category->parent != $category_ID) { // it's not direct child
$parent_category = get_term($category->parent, 'product_cat');
if ( $parent_category->parent != $category_ID ) { // it's not grandchild either
unset($categories[$k]);
}
}
}
Related Posts:
- How to Display Product specific to a category with WooCommerce Plugin? [closed]
- How can I allow commas in tag names?
- Way to force media uploader use custom image size
- Restrict individual category combinations
- Restrict access and display for categories
- Qtranslate displays empty categories with get_categories()
- Plugin for changing a post’s category based on it’s post date?
- Woocommerce category description as subtitle
- Get subcategories with JSON API plugin
- How to show custom static content at top of each category page?
- How to use get_categories() with Event Organiser plugin
- Server-side subscribe by email?
- plugin for wp_list_categories with posts
- Set a category for a page
- Show Heirachy of categories in WP Download Monitor
- Custom Post Type Plugin not loading category template and loading 404 instead
- How can i list random post from multiple category?
- My Category is too big on the Menu what can i do?
- Getting a List of Categories for Use in a Plugin?
- Not able to open category post [closed]
- WordPress JSON API remove posts from a specific category
- Easy Digital Download Sub category
- Solutions to repost categories into multisite blogs?
- Category’s Description field as editor remove tag
- Assign post format to categories
- Using WP Category Lists Plugin to Dynamically Display Category (PHP)
- Calendar Solution: Handling upcoming Dates with Posts?
- Events Plugin that works with existing categories?
- Trouble with editing template for “List category posts” plugin
- Any built-in function to associate a post to category through a plugin?
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- Display by Category in Admin
- Search for categories
- Redirecting thousands of posts that currently have no category in their permalink when changing permalink structure to include category
- Automatically Assign Author to Category [closed]
- WordPress “Categories to tags converter” not working. Pointing to import.php instead
- How do I apply style to each category of a list?
- Redirect to another page using contact form 7? [closed]
- Recent posts per category loop?
- How do I rename a category in the menu bar only?
- Ambrosite Next/Previous Post Link Plus or WP next_post_link to cycle through top level category
- Is changing post from category in a large blog a good practice?
- How to set category correctly for a custom post created by a remote API call?
- check uncategorized category by default
- How to add category and subcategory in WordPress custom code?
- WooCommerce Hiding A Certain Category From Being Displayed On Single Product
- How can recognize post’s category?
- How can i listing current category and Featured Category post list?
- How to get Recent Post From Each Category with Thumbnail?
- Category “same post” retreive and display
- Add a new category for posts
- How to overwrite the category template in a plugin
- how to show all posts of each category in pages
- Custom Post Type same name as Category
- Visual composer custom element error
- How to display the category name in the tab and post inside the tab in WordPress?
- Adding custom post category to categories widget
- Custom Post Type with Sequence ID
- WordPress default post categories meta box widget
- Getting the same post on my related post
- What plugin would make this happen? If is the theme
- how can I edit the HTML of yith ajax product filter
- Unset plugins on front-end belonging to specific category
- WordPress Categories as a Grid
- Trying to remove a couple categories from shop page
- How to allow editors to only edit certain categories?
- Category as Subdomain for One WP Install
- Woocommerce categories displayed on every category and shopping page
- Ajax Load More on Hierarchical Categories
- Sub Categories in drop down menu
- How can I display a list of only categories which are marked as ‘featured’ in the backend?
- Related post based on 2 categories
- View more posts of a sub-category
- How to insert category name above post title in a featured pages plugin?
- trying to create simple plugin to filter categories from all authors
- WordPress Categories from Plugin
- Show all posts of all categories but excluding a category on custom blog page with pagination of my theme
- Is it possible to setup Category wise Subsciption?
- CSV file header
- Retrieve post thumbnails
- Synch Custom Post Types (and Custom Fields, Cats, etc.) Between WordPress Sites
- How to add character to content of post?
- Editing “Kahi’s Highlight Used Categories” plugin code – highlighting parent and child category in post page
- single.php fires more than once after clicking on any post to view with different post id each time
- How can I add the custom taxonomy categories to the posts and pages?
- Twitter List Tweets and Delicious Links as Posts
- WordPress “Categories to tag converter” not working on imported Blogger posts
- wp_insert_post_data filter to set category
- What happened to WP No Category Base?
- Is there a way to combine categories and their hierarchy into the admin listing page?
- Save post to category with gravity forms (post_data) [closed]
- Make a Custom template for a specific category in wordpress
- woocommerce retriving category name as div class?
- query_vars in plugin when using custom permalinks
- How to pre-set WordPress settings for specific posts?
- How to make horizontal scrolling menu [closed]
- Create WordPress category dynamically
- Can i have limit posts on a specific category and automatically remove older ones?
- Categories not showing when all of the posts are private
- How to add portfolio category post count in main navigation menu?