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
- Custom post type URl Cutomization
- Correct procedure for advanced permalinks
- Permalinks: custom post type -> custom taxonomy -> post
- List Taxonomy Terms based on another Taxonomy
- How to get the intersection of two terms both from different custom taxonomies
- CPT’s with landing page instead of archive – Url Rewrite?
- Template for all categories of a custom post type?
- How to change permalink to include custom post type
- Add Custom Post Type of specific Custom Taxonomy to regularly blog loop
- posttype/taxonomy/term archive page 404 error
- How to add attributes to taxonomies that may be different from post to post?
- Display taxonomy terms, child terms and posts in a template
- Custom post type, permalinks, taxonomies and blog posts
- How to group posts and get a mixed posts and groups view?
- Custom post type permalink tag 404
- How to make front end form only accept certain values
- How to get list of taxonomy slugs ordered parents>childs?
- Custom Post Type by Taxonomy
- Deleting taxonomy terms and relationships on a custom post_type when a user is deleted
- Custom post type / taxonomy rewrite archive page 2 gives 404
- Use custom walker to add taxonomy terms to main nav menu
- Post format alternative?
- WP_Query orderby and tax_query
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- browse by category and tags?
- permalink /category/post-name with custom post type and taxonomy
- Taxonomy structure help
- Querying Custom Post Type, ordering by Custom Taxonomy Pagination Not Working
- I am trying to hide a custom post type category to logged in users with Pre_Get_Posts
- Custom Taxonomy not being saved on custom posttype
- Create more category hierarchical depth for custom post type/taxonomy plugin (widget)
- Displaying Custom Taxonomies From Multiple Custom Post Types
- Hierarchial Custom Post Types/Taxonomies
- Custom post type and taxonomy permalinks
- How do I share categories across multiple post types?
- Exclude custom taxonomy term posts from custom post loop
- Hierarchical permalinks for custom post type and taxonomy
- Migrating a taxonomy’s tags to the native category
- Add term to custom post type on draft
- Multiple tag cloud filtering
- Can slugs from posts and custom post types conflict?
- List of Posts and Categories
- Grouping of CPTs and taxonomies into menu groups in admin
- Best way to organize book-page structure
- Get url.com/post_type/taxonomy/term work!
- Displaying custom-taxonomy-terms sorted by parent/child-hierarchy?
- Invalid argument supplied in register_taxonomy $args->taxonomies
- set permalink for CPT
- Top Level pages in wordpress giving 404, but child pages working fine
- Sitemap generation
- Plugin fatal error
- Custom Post Type – Duplicate Page Slugs
- How to display products name in a non-alphabetical order, in a custom field (taxonomy)?
- Taxonomy/Custom post type structure suggestion on a movie site
- Search by tag name and category
- Taxonomy in URL
- Ordering values entered in Custom Taxonomies