You can use the get_the_terms
function, which will return an array of objects, each representing a category, and each containing the id of the term as well as the id of its parent, if it has one. You can use this data to determine which is the parent and which are its children.
Also see this post by Scribu on using a custom category walker to filter wp_list_categories
, limiting output to terms associated with a particular post, giving you a proper tree structure.
Related Posts:
- Permalink Structure for Multiple Post Type Archives by Taxonomy
- Taxonomy, Terms, and Template Files
- Exclude a category from WP_Query
- Get Custom Taxonomy ID within loop
- Custom Post Types not showing on Custom Taxonomy archive page
- custom post type or taxonomy
- How do I Filter Custom Post Type by Custom Taxonomy in the newest WordPress RESTful API?
- Changing the priority of a custom taxonomy’s metabox
- How to list all categories and tags in a page?
- TV Show database – Best way for structuring it?
- How to setup a Custom Taxonomy Term template
- Admin to user notices – best practices?
- Retrieve a specific field from taxonomy term through advanced custom fields [closed]
- Many to Many Taxonomies or rewrite rules?
- Query posts by custom post type and custom taxonomy
- front end radio custom taxonomy with custom post type
- How to display the rest of categories on Portfolio filterable
- Bulk 301 redirect for custom post type
- How to query custom post type by term?
- ‘category__and’ for custom taxonomy?
- Custom post query by taxonomy
- Custom Permalink with Dynamic Taxonomy for Custom Post Type – Works, but breaks other permalinks
- How can I show recent posts from same taxonomy as the post currently being viewed?
- How to get the first term for the current taxonomy?
- Group custom posts by custom taxonomy names
- Display Posts in Custom Post Types Timber
- How to query custom post types posts filtered by multiple custom taxonomies through a form selection
- Get post from custom post type order by two taxonomies
- How to convert custom post type based list to a dropdown list?
- Wrong request query on cpt and tax
- Getting a PHP Notice when using Pods with WPML [closed]
- Display post as term id
- How to filter wp_list_categories output with some custom post type meta query?
- Custom taxonomy rewrite give pagination 404
- Removing custom post type slug from URL
- Customize Custom Post Type URL
- Advanced search form with filters for custom taxonomies
- Custom permalink with child taxonomy terms
- Why cant I add a custom post type to a custom taxonomy?
- Show Custom Taxonomy title in loop
- WP the_posts() on single-cars.php get category link
- tax_query not working in template
- Custom Taxonomy Not Showing in Front-End When Outputting a Custom Post Type with WP_Query()
- Custom Post Type Dilema – How do I categorise by country?
- Custom post type’s extra fields – how to handle?
- Display custom taxonomy on my custom post type
- List Categories (wp_terms) and count posts
- Can I query posts by taxonomy conditionally based on post type?
- Which file/template is in charge of taxonomies for custom post types?
- Custom Post Types not queried in Custom Taxonomy archives or Native archives
- Show current custom taxonomy
- Include custom post type custom taxonomies in Categories widget
- CPT Taxonomy As Archive Page – Error 404
- Changing CPT slug and taxonomy already registered in parent theme
- Show post count number assigned to custom taxonomy
- List all Custom Post Type posts excluding certain Taxnomy term
- Can’t pull posts of a Custom Post Type based on the custom taxonomy of the CPT
- Conditional Statements
- Check when the post type changes, and display content
- Loop and add Specific Categories and Products Images
- Custom post type specific category box
- Making a form for user to add new custom post with custom taxonomies and custom fields
- custom post type or taxonomy, which approach is better?
- Taxonomy terms with the same name are updated between separate custom post types
- Custom Post Type with Different Sets of Post Content?
- Custom taxonomy permalink without term, redirection to CPT slug
- Add a class to a div if custom post type has specific terms?
- Custom Permalink For Custom Post Type – Working Fine But Broken For Pagination
- Custom post type paging return home page
- Basic CPT Question About Categories
- custom post type and a “sticky” position taxonomy
- Custom taxonomy returns 404 even with saving permalinks
- WP_Query to display number of custom post type filtered (order by) taxonomy
- Custom post type shortcode with taxonomy attribute not working and no errors
- Redirect Custom Post Type from Child Taxonomies
- Ajax load more inside custom post type taxonomy
- How can I get the last 5 element of this tax query?
- Custom post edit page permalink links to edit page rather than the post
- Create a custom wp_query from a specific custom post type with specific taxonomy
- URL with Hierarchical Taxonomies and same slug for all terms and sub-terms
- Show tags of custom post types in WordPress
- Show posts for current taxonomy
- order taxonomy alphabetical
- WordPress get all post with like in terms [duplicate]
- Custom post type archive page not showing on archive-posttype.php
- Query Pulling the same post twice
- Cannot retrieve Custom Taxonomies (Disappeared)
- Custom Post type and Taxonomy in post URL error
- Display Custom taxonomy, Child terms and posts in a template Under Specific Parent terms
- Render custom taxonomy query as single template
- Custom meta-box for all custom post types
- Loop multiple taxonomy in custom post
- Sort a custom post type loop by a custom taxomomy instead of chronologically
- How to Create Custom Post Type with Multiple Color Options?
- Add custom taxonomies as class names to an archive page of custom post types
- Listing all custom post types using a specific term on the said term’s template page, in groups
- Require Custom Taxonomy for Custom Type
- Get all active posts that are tied to a custom taxonomy for a custom post type
- Dynamically count the number of custom post types associated to a custom taxonomy
- Taxonomy Archive URL + Template