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
- Shouldn’t this be easy?! Custom post type/custom taxonomy permalink
- Combining Multiple Taxonomies in one URL
- Getting the Intersection of Two Custom Taxonomy Terms for a Custom Post Type?
- Why does my custom taxonomy show a total count across all post types
- How can I list all the categories under a Custom Post Type (taxonomy)?
- ‘No pages found’ in Dashboard after registering custom taxonomy
- Custom Post Type with Nested Taxonomy and Template Files
- How to display recent posts added in custom post types
- Should unaltered default loop/query return a list of custom posts belonging to a custom taxonomy?
- Creating a function that receives the taxonomy terms that have been changed in a custom post type
- Query for posts in 2 taxonomies
- Permalinks when filtering multiple custom post types by single taxonomy
- Filter custom post type archive page with custom taxonomies (categories) with AJAX
- How can I filter by taxonomy on a custom post type’s page?
- Can custom taxonomies items have attached properties?
- How to Get Current Custom Post Type Selected Taxonomy Term (Not All Terms)
- Update post terms with custom taxonomy
- Deleting Custom Taxonomy Term only increments tag_ID
- Get custom post type list for every category shortcode
- getting all values of a custom taxonomy if there is no post
- Listing tags from a custom post type
- How do I associate a custom post type with another through a taxonomy or storing an ID in a custom field?
- How Can I Change the Custom Post Type Slug to the Taxonomy Slug in the URL?
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- 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?
- Get related posts of child term of custom post type
- Filter term taxonomy metabox in custom post type
- Show custom post archive when custom post not specified
- Show custom post type relationships by taxonomy
- Custom Post, set object Taxonomy terms in plugin
- Hierarchy and access control for Custom Post Types (CPT)
- How to get list of taxonomy slugs ordered parents>childs?
- Custom post type / taxonomy rewrite archive page 2 gives 404
- Sort posts in loop by the WooCommerce Membership of the author
- single-{post_type}.php not working
- Loop through custom posts by taxonomy and display the titles in a list, it is repeating 8 times
- How to add current custom taxonomy slug to body class
- Custom post type, custom taxonomy, query posts only from taxonomy (children of)
- How to define a term for custom taxonomy
- Exclude posts with custom taxonomy
- Get parent category(taxonomy) ID from single template of a custom post type
- Dynamic CPT / Taxonomy
- How to approach a site where it has sub-businesses, each with its own pages (“articles”, “staff”)? Don’t want to use WP multisite
- Get the link of the first post of a custom taxonomy in a custom taxonomy list
- Get custom term meta problem on single post type
- Creating custom post type posts and associating them with a post from another custom post type
- Different structure/content for posts from a custom post type
- Custom Post Type URL Rewrite’s
- Add term for custom taxonomy from front end
- Custom Taxonomy Filter Issues
- how to organize my categories or should I do custom post types for some?
- How do i display post from a taxonomy term?
- Multiple permalinks for a single post with multiple taxonomies
- rewrite rules hierarchical
- Auto Generate Post Title from 2 Custom Fields
- How do I make a request in my browser to search the CPT taxonomy?
- Archive page of taxonomy returns a 404 error
- Custom Post type to Woocommerce Product type
- Get dropdown child categories from parent category of custom post type
- How do you create pillar content pages?
- How to display “META” array in register_taxonomy
- I want to create a metabox under custom taxonomy
- Grid slider with custom post type (how to filter with taxonomies?)
- Customise Permalink Structure For Custom Post Types
- CPT/Taxonomy/Postname permalink structure makes pagination break
- Set different posts_per_page for custom post type/taxonomy
- WooCommerce breadcrumb display custom posts instead of product data
- Facing some Issues on Two Parts Custom Post Type Taxonomy Names
- I want to create an archive and single page for a custom taxonomy for a custom post type
- Taxonomy’s title
- Display all posts from single taxonomy term
- Creating adminable dynamic filtering on custom post type
- Best way to use Category & Custom Fields?
- WP_Query for CPT with filter by another WP_Query
- Get posts in same category not working
- Heirarchical URLs with CPT and custom taxonomy
- Displaying taxonomies with manage_{custom-post-type}_posts_custom_column
- Plugin Error on activating
- Permalinks when using Custom Post Type with static page for archive
- How to change permalinks to taxonomy and post type’s posts
- Paginate custom taxonomy category with wp_custom_pagination
- Parent cpt/child custom post type URL permalink relationship
- Query Only Show Text on Posts With Certain Taxonomy Tag
- Custom Taxonomy Showing in WP Menu
- Storing/querying custom date data
- Custom Template Taxonomy
- How to relate one custom post type to another custom post type
- How to make a single Menu Item call another Mega Menu for Custom Post Types and Custom Taxonomies?
- Links in archive not including taxonomy parameter
- Permalinks for Custom Post Types and Taxonomies