When asigning a post to a taxonomy, if you assign it to both a top-level and child term, the top-level will be used in the permalink. If you only select the child, I believe the parent term will be displayed as well. I agree, that this is not ideal and you may be able to work something out with wp_rewrite()
but there’s an easier way to get the parent term:
On the post page you’ll need wp_get_post_terms()
. This will return an array of terms associated with the post. If you only want the top-level term for the post, pass parent = 0 in the args array as I’ve done below.
$args = array( 'parent' => 0 );
$terms = wp_get_post_terms( $post->ID, 'taxonomy_name', $args );
echo '<pre>' . print_r( $terms, 1 ) . '</pre>'; // raw output
Related Posts:
- Theme localization of “slugs” (custom post types, taxonomies)
- Custom Post type & Taxonomy URL structure
- Combining Multiple Taxonomies in one URL
- Taxonomy archive with same slug as custom post type?
- Dynamic taxonomy in permalink made all other posts NOT FOUND?
- Remove taxonomy slug when not assigning taxonomy with custom post types
- Rewrite CPT slug with two taxonomy slug instead of one
- Remove Taxonomy Slug when No Taxonomy is Assigned to Custom Post Type?
- Custom Permalink with Dynamic Taxonomy for Custom Post Type – Works, but breaks other permalinks
- Custom Taxonomy breaking pages permalinks
- Custom Post Type with two hierarchical Custom Taxonomies: strategy to generate best permalink structure
- Custom post type and taxonomy slug issue
- Does WordPress limit the length of slug names for Post Meta or Terms?
- How can I make the slug of the taxonomy also the slug of the custom post
- Allow duplicate slugs for custom post type with taxonomies
- Nested Custom Post Type or Custom Post Type Parents?
- Including taxonomy term before post type breaks top level pages
- Rename a slug label
- Different slug taxonomy for two different CPT
- How to add current custom taxonomy slug to body class
- Using page slug in wp_query
- Listing all slugs?
- Custom Post Type Advanced Slug
- Changing CPT slug and taxonomy already registered in parent theme
- How do I set a post slug automatically based on taxonomy?
- Custom post type and multi taxonomies + customize url
- Use custom post type taxonomy between cpt slug and name
- Remove custom taxonamy slug with pagination
- How can I write slugs / permalinks as: custom post type -> custom taxonomy and custom post type -> custom taxonomy (one CPT and many taxo)?
- Custom post type URL structure with site.com/custom_taxonomy_slug/post_name
- Custom post type post_type_link gives “page not found” on any other custom post type
- Custom taxonomy archive slug overwrites static page
- Slugs on hierarchical taxonomies
- Display a Custom Post Type within another with hierarchically slug
- Getting a 404 on single custom post type page when using rewrite on a custom taxonomy
- Remove Custom Taxonomy Slug only without removing Custom post type slug in permalinks
- WP Query Post Type with same Taxonomy name
- WP Query WordPress Post Type with the same Taxonomy name
- Custom Post Type with multiple Custom Taxonomies / Hide Taxonomy Slug from URL
- Hide custom post type slug url from search engine [closed]
- Same slug for Custom Taxonomy archive and CPT archive – Rewrite rule not working
- Is it possible to use a post name in a custom post slug?
- Taxonomy Archive URL + Template
- Exclude a category from WP_Query
- Check if post type has term
- How do I Filter Custom Post Type by Custom Taxonomy in the newest WordPress RESTful API?
- Custom taxonomy not showing up when adding a new custom post type
- WordPress custom taxonomy URL rewrite on spelling errors
- TV Show database – Best way for structuring it?
- Rewrite permalinks for custom posttype and custom taxonomy
- How to check if last uri segment is a custom post type or taxonomy term?
- Query posts by custom post type and custom taxonomy
- Sort the main query in subcategories/terms?
- Getting Post ID from slug during init
- Highlight nav menu terms
- Custom Post Types, Custom Taxonomies and Permalinks ?
- Display Custom Category (taxonomy) Name in Custom Post Type
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- removing custom tax & CPT slug, adding taxonomy term in front of custom type
- Order WordPress Custom Taxonomy Pages & Pagination Not Working
- Custom Post Types relationships
- How can i skip same post from taxonomy term?
- Set menu active state for custom posttype and category, given custom taxonomy term
- Getting a PHP Notice when using Pods with WPML [closed]
- Custom post type structure for posts with multiple child posts
- Extending AZIndex plugin to use custom post types and custom taxonomies
- How to display custom taxonomies with links in filter menu?
- List custom taxonomy specific to one custom post type
- Hide parent categories when clicked, and show it’s childs
- Get unique superset of taxonomy terms from a list of custom posts in another hierarchical taxonomy
- Multiple (two) category postings on the same page.
- Auto Complete Search
- permalink /category/post-name with custom post type and taxonomy
- Custom post type Permalinks with hierarchical Taxonomies
- Slug for custom post type
- Can’t use pagination with custom taxonomy
- Hide specific taxonomies from a taxonomy list using ‘get_object_taxonomies’
- Targeting categories in custom fields
- Displaying tags associated with posts in Custom Post Type
- Custom taxonomy page returns 404
- Targeting custom post type via functions.php doesn’t work
- How to define the template for custom posts?
- Multiple archives to display parent and subcategories content
- How to List Custom Post Type Titles Based on Theirs Taxonomy Terms Inside a Nested Loop
- Custom Post Type and Taxonomy Rewrite Error
- how to retrieve related projects in a post but via a custom taxonomy?
- How do I Create Single template for custom post type with a custom URL?
- Show posts from custom post type sorted by category/taxonomy on a one-pager/page
- Query a custom taxonomy in a function to create an csv file
- Categories manage
- Taxonomy Page Go to 404 pgae
- CPT url rewriting : regular posts return 404 error
- Need some suggestion/help with custom post types project
- Custom taxonomy page template
- tax_query showing no results
- Sort a custom post type loop by a custom taxomomy instead of chronologically
- changing post type in loop query
- Taxonomy and Rewrite Structure
- Add custom taxonomies as class names to an archive page of custom post types
- Custom Post Type Base URL