It sounds like you’re looking for get_ancestors()
. In your case, something like get_ancestors( $term_id, 'product_cat', 'taxonomy' );
should get an array of ancestor (parent, grandparent, etc) IDs for a given $term_id
.
Related Posts:
- Cloning product not copying custom taxonomies
- Display woocommerce product_cat child terms with thumbnails
- Exclude specific slug in ‘get_terms’
- Is there a way to disable a term rather than deleting it?
- Modify Term Update Redirection
- Return only the custom sub-term for custom post type, do not echo term-parent
- Check if current term is a child of another term
- get_terms() doesn’t return empty terms even though hide_empty is false
- Formating the_terms() function output
- Custom Taxonomy Only Showing Top Level Terms in Admin?
- Get current term’s ID
- Is it possible to get a Previous/Next Taxonomy term archive URL?
- Looping Through Custom Tax Terms and Displaying All Posts For Each
- How to get the top most term (top ancestor) of a custom taxonomy child term?
- How to set hierarchical terms to a post using wp_set_object_terms
- Echo taxonomy term meta on author.php
- Hierarchical display of custom taxonomy
- How to display term description in empty terms archive?
- Checking if a Page has an Associated Term?
- What are terms and taxonomy, how they related to post and how these three are stored in database?
- Taxonomy , subtaxonomy,child taxonomy of a product woocommerce
- Get terms ordered by post date
- Allow only 1 instance of each term in each custom taxonomy
- Outputting an array of term meta values in a custom WooCommerce tab?
- get_the_terms() to show all custom taxonomies
- How can I get WP to build a feed based on multiple taxonomy terms
- get_terms: determine if taxonomy term has children
- Programatically added attribute, set to ‘show on product page’ automatically. Woocommerce [closed]
- Get child product categories from parent product category in WooCommerce
- display taxonomy slug from term ID
- get_term_children doesn’t return an array of children terms
- Get Current Custom Taxonomy ID by Post ID
- Changing stylesheet depending on custom taxonomy terms
- Taxonomy archive showing no results
- Use get_the_terms to list subcategories of custom taxonomy
- Get custom category image from menu
- get_term and get_term_by return null or false, even though term exists
- Display Taxonomy Terms in an option tag with value being the slug
- Changing taxonomy term by slug (wp_update_term)
- Hide product categories and taxonomy terms in menu if empty
- woocommerce custom product category template
- Getting WooCommerce product related child categories
- Displaying Custom Taxonomy without a hyperlink
- Get only immediate children (and not grandchildren) of a hierarchical custom taxonomy term
- How to group all terms children’s in custom taxonomy?
- Show template part if part of term
- one post per term taxonomy
- How can I change the output display of my pagination?
- Exclude product attributes from taxonomy terms loop
- Corrupted nav-menu?
- Get name of taxonomies of current page
- List Top 5 taxonomy terms based on number of post
- Order taxonomy terms wordpress
- Unable to get the Parent Custom Taxonomy Terms
- How to get the term description in a taxonomy term archive query?
- Unsetting post_tag taxonomy breaks term description for other taxonomies
- Use wp_list_categories to list parent categories from actual term
- Include get_term_link inside search
- Trash Bin for Categories?
- Set two terms for a post when they differ only by an accent
- Retrieve the child terms by having the parent’s information
- Fill New Taxonomies
- Infinite Scroll appending Next Product Category Term pages
- add pagination in wordpress page template
- Listing Cities A custom taxonmy by selection order
- Get WooCommerce product category list in functions.php
- How to create a non removable taxonomy term?
- Filter “get_terms” query
- generate random slug when adding taxonomy
- Get Highest and Lowest get_term_meta() value from Taxonomy Term
- How to get a terms and posts associated with another term?
- Displaying subcategories and then posts in taxonomy template
- Why get_terms() behaves strangely when being called in admin (for use in meta box)?
- set_object_terms for custom taxonomy in custom post type – not working
- qtranslate-x problem with custom term description
- Resize $term attachment using url
- Custom order of taxonomy using wp_get_object_terms and woocommerce_term_meta
- switch statement for taxonomy content
- How do you search for a post by custom taxonomy?
- Display taxonomy term slugs
- Taxonomy term breadcrumb; how?
- Exclude 2 in 3 terms of A Taxonomy from all Archives
- get_terms() – unexpected ‘=>’ (T_DOUBLE_ARROW) error
- Issue On Listing Woocommerce Parent Tag List
- How to delete unused terms?
- Hide empty categories on widget
- Custom taxonomy on permalink
- How to return a list of custom taxonomy terms via the Gutenberg getEntityRecords method
- term_link() filter or rewrite and howto?
- Get terms from posts submitted within a certain time
- Display post taxonomies tree
- Wrapping result of the_terms in a span with a class of the term name
- WordPress implode & wp_insert_post question
- How to write sql query to get the posts from a custom taxonomy term name
- Build filter for post-type + multi taxonomies + multi terms
- get_term_by works but get_terms doesn’t?
- How to output taxonomy term (incl. link to archive) on author.php?
- how to show product custom taxonomies in woocommerce rest api
- Permalink Rewrite to include Custom Taxonomy Term
- How can I get parent term from a child term