Top level categories will have value 0 for the parent, so check that before adding to the array:
foreach( $categories as $category ) {
if( 0 != $category->parent ) {
array_push( $cat_ID, $category->cat_ID );
}
}
Related Posts:
- Exclude category from category archive
- Better way to exclude category output for post/pages?
- Exclude Categories from wp_list_categories()
- Display 1 category only with get_the_category (by ID or slug)
- Get first category only and excluding one
- exclude category from get_posts?
- Exclude the category from the WordPress loop
- Exclude certain category from latest updates
- Exclude categories from Loop, queries, widgets, post navigation
- List posts by category exclude current post
- wp_list_categories exclude not working
- How to filter by category in REST API, excluding posts also in other category term?
- Exclude Tags from get_the_tags
- Excluding a category from next and previous post links
- is there a quick way to hide category from everywhere?
- Exclude Category From Home Page, Display Posts on It’s Own Page?
- How to exclude categories from recent posts, recent comments & category widgets?
- Exclude a category from the filed under list only on some templates
- How to set post expiration date and time and move the page to archive after expiration [closed]
- How to exclude posts from a category when using this particular format
- Exclude category from Tag Template
- exclude post from displaying in loop if it is in a category, but not in many categories
- I need to create a search form that will display search results from specific category
- Exclude Posts From Specific Category from Next and Previous post links
- Query Posts Exclude Entire Category
- exclude categories from search results
- Exclude category from fucntion
- WordPress category widget only show categories with children
- Exclude Category filter from Portfolio section
- Multiple arrays in post__not_in parameter
- Excluding posts not working
- wp_list_pages() exclude category
- Include posts from some categories while excluding from others
- Loop doesn’t exclude the specified category in home page
- How do I remove a category from a wordpress loop>
- Exclude category from query
- Functions.php: Exclude Category from “Blog”
- Exclude Category ID in function
- Woocommerce filter function not updating
- How to get post with slug and exclude categories
- wp_list_categories not excluing multiple ids
- Exclude post category in a blog page
- How to exclude posts from category posts count
- Exclude category from foreach loop
- Have posts that belong to multiple categories, exclude some categories from homepage
- Exclude all subcategories in the_category (post)
- Exclude some categories from the post page
- Exclude category from get_the_category
- I need to exclude from a query a category and a few custom taxonomies
- Exclude categories by ID
- Don’t execute function on specific posts
- WooCommerce Hiding A Certain Category From Being Displayed On Single Product
- using pre_get_posts to exclude
- Homepage custom recent news
- problems exluding categories
- Exclude the category in WordPress
- How can I exclude a category from the main loop with the category name & not ID?
- User level categories
- Exclude category from drop down list form
- Disable the link on certain pages
- exclude certain categories form archive widget
- Exclude Woocommerce Product Category From Sitemap
- How to remove an item from a custom Walker_Nav_Menu
- Exclude a category and post_type from wp_query
- Exclude category and post from loop in custom category.php
- How can I exclude a particular category from my WordPress Page 1 and Page 2?
- Excluding category from post navigation in WordPress?
- post__in and tag__not_in conflict
- Exclude category from WP_Query args not working
- Displaying Category in sidebar post widget but not in the loop on home
- How to exclude one category
- How to exclude a category in the following Code?
- Category menu that filters out empty categories
- trouble with my loop
- Problems with explode [closed]
- Exclude Category From Home Page, Display Posts on It’s Own Page?
- How to have a category not show up in query post with page panigation?
- Customize category query in widget
- Exclude a ‘portfolio’ custom category?
- Call function on a single page
- Excluding cateory not working on my site. how to solve this? [closed]
- How to define category ID in an array?
- hide particular category post from front page only [closed]
- Exclude a category ID from the following function
- Set a them for all subset of category
- How to query post like normal search would do. within search.php page
- Getting categories of posts under a custom taxonomy
- Exclude the first ‘n’ number of posts of a tag from home page?
- how to show single post in a custom template
- Adding a H1 Tag to Post Tags automatically, but hide the tag? (Same for Category)
- Insert post’s category name into thumbnail string
- How to detect /category and /tag base pages?
- Dropdown category field inside repeatable metabox
- Only 10 of 233 categories selectable when adding a new post
- Woocommerce categories displayed on every category and shopping page
- Do not output category and tag URLs
- WordPress edit.php category filter to show only posts from direct category and not posts from it child category
- Delete Term via edit-tags.php
- How to list out post category name and description in page
- Is there a way of displaying related posts from lowest hyrachical order (lowest child category to parent category)