Using wp_list_pluck
to return an array in the form of array(term_id => parent, ...)
, you can do the following (explanation is given in the comments):
$variations = get_the_terms( the_ID() , 'product_cat' );
if(is_array($variations)) { //make sure terms were returned
$parents = wp_list_pluck( $variations, 'parent', 'term_id' );
foreach ($variations as $variation) {
if($variation->parent && $parents[$variation->parent] && !$parents[$parents[$variation->parent]]) { //if parent's parent has no parent (parent==0) i.e. a top level term (0 evaluates to false when treated as a boolean)
//display term
}
}
}
Related Posts:
- Exclude a term of a taxonomy with a custom post type in a search
- Get post from custom post type order by two taxonomies
- Get Terms from Custom Taxonomy and Current Post
- WooCommerce – Custom related product (Spareparts)
- Custom Taxonomy not working front side Woocommerce
- Custom Taxonomy is disabled on Edit page
- Complex strcuture as CPT or taxonomy for use in woocommerce product variations [closed]
- How to manage a bookstore
- Issue On Listing Woocommerce Parent Tag List
- Custom Post Type – No Results Found
- Return the latest post from a custom Taxonomy and Post Type
- Cannot add category or custom taxonomy from admin. WordPress site is hosted in Windows 16 server via IIS. No XAMPP or WAMP
- Don’t know how to show custom taxonomies from a custom post_type
- How to Filter custom post type by taxonomy?
- 404 error when navigating to a taxonomy page with Cyrillic, what’s wrong?
- Custom taxonomy rewrite give pagination 404
- How to duplicate entire custom post type
- Displaying CPT and custom taxonomy side by side in Bootstrap 4 component
- Use Custom Post Type archive page for the taxonomies term archive page
- How Can I Change the Custom Post Type Slug to the Taxonomy Slug in the URL?
- Is it possible to have dedicated page for parent/child taxonomy?
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- Can a Custom Taxonomy be named “category” like normal Posts?
- How to use terms from the same custom taxonomy in different roles in a custom post type?
- How to have the same url structure for both a CPT and a Taxonomy?
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- create a subcatagory for a custom post type and out put url as posttype/subcategory/item
- How do I display the taxonomy term alongside the post type post title?
- Display custom post type category, while in a CPT category, then the posts beneath
- Why are taxonomy terms not saving when using custom meta boxes with radio button taxonomy selectors?
- Display Custom Toxonomy In WordPress and theme Widgets category selection dropdown list
- Hide parent categories when clicked, and show it’s childs
- WP_Query inside foreach loop returning same value for all options when filtered using ajax
- Hide post navigation if current post is in a category with only one post
- Get related posts of child term of custom post type
- Limit amount of posts made within a custom taxonomy
- custom-taxonomy/post_name instead of the default post_type/post_name
- Filter term taxonomy metabox in custom post type
- Show custom post archive when custom post not specified
- Show custom post type relationships by taxonomy
- Group CPT posts by custom taxonomy
- Issue on Creating Custom Tax Term Dynamically From Another CPT Meta-box On Publish
- Filter CPT posts by one or more categories
- Custom taxonomy and custom post type – wrong permalinks and template
- Setting up taxonomy to relate various custom post types – advice on structuring?
- Getting categories of posts under a custom taxonomy
- Post count by month of taxonmy term
- How can I make the slug of the taxonomy also the slug of the custom post
- Query taxonomy of taxonomy of custom post type
- Taxonomies don’t show up on in the dashboard page for a custom post type in wordpress 5.22
- Can’t remove front from permalinks for custom taxonomy category page
- Custom WP Query on custom meta and sort by multiple meta keys value
- Woocommerce search pagination not working
- How to checked selected category checkbox when my custom post inserted from frontend
- Allow duplicate slugs for custom post type with taxonomies
- WooCommerce Customer Role Delete Custom Post Type
- list taxonomies from a custom post type
- How to display Custom Taxonomy under Custom Admin Menu?
- Display a grid of taxonomy terms at root taxonomy page
- WordPress custom taxonomy, posts urls
- Listing posts under primary and secondary taxonomies
- Removing custom post type slug from URL
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- How can I made custom taxonomies relationship?
- How to start a new post with custom Taxonomies already set?
- Nested Custom Post Type or Custom Post Type Parents?
- Customize Custom Post Type URL
- What’s the WP way to load remaining custom posts?
- WooCommerce sort products by the actual product width(not the shipping width)
- Manage custom post type in woocommerce /my-account/ page
- How to rewrite url for any specific taxonomy?
- Specific query for custom post type
- Custom post URL 404 error
- limit value taxonomy based on previous taxonomy value wordpress
- Dynamic dropdown select values depending on other custom field value
- Get unique superset of taxonomy terms from a list of custom posts in another hierarchical taxonomy
- How do I change the custom taxonomy slug to be the same as the custom post type slug?
- Limit number of custom posts per taxonomy
- Custom taxonomies relationship
- I want to change the word “Tags” in WordPress to something else, but how?
- Permalinks /country/city/cpt/postname/
- Number of Custom Post Types published are not being shown in the custom page
- Seamless permalinks between Custom Taxonomy and Custom Posts
- Woocommerce custom field search in custom post type [closed]
- Custom post type and custom taxonomy with the same slug using the file page taxonomy only as directory
- Metabox not show in categories custom post type cmb2
- What is the best practice for displaying my plugin content in themes?
- Categorize custom post type
- How do I display the taxonomy for a custom post type in an array
- Pretty URL for custom search for custom post type
- Custom taxonomy rewrite with query var returns %2F in URL
- WP Rewrite Rule Issue while using Custom post type & taxonomy
- How to list custom taxonomies in the back end
- Several CPT’s with same Taxonomy name but with different Terms for each
- Remove slug in URL custom post type
- Custom Permalinks with CPT and Hierarchical Taxonomies
- How to conditionally redirect to the post from a taxonomy page?
- How do I check if the user is on a taxonomy term parent, child or grandchild page?
- Sort and filter custom post type posts by custom taxonomy
- How do I display the grand child items of a taxonomy term?