It took me two days to figure this out in the proper way, so I’ll add it here for anyone else that may need it in the future.
add_filter('wp_unique_term_slug', 'prevent_cat_suffix', 10, 3);
function prevent_cat_suffix($slug, $term, $original_slug)
{
if ($term->post_type == 'product' && $term->parent !== 0) {
return $original_slug;
}
return $slug;
}
As you can see in the code, I’ve narrowed it down to products only, but you can make it suitable for any other post type also by removing the $term->post_type == 'product' &&
in the code above.
Related Posts:
- Archive page showing nothing – issue with WordPress Hierarchy?
- How to make a list that displays the top level subpages, and any subpages or siblings off of the current page
- How do i get the direct neighbor in a hierarchy
- HowTo preserve page hierarchy with wp_list_pages()?
- get all levels parents from id term
- Will renaming a `content.php` file cause any problems?
- (get_post_ancestors == 2) is returning true on 1 as well?
- Hierarchical types and page size problem in heavy sites
- How to show a hierarchical terms list?
- Get the the top-level parent of a custom taxonomy term
- How to Check if a Page Exists by URL?
- set a CPT as parent of a page
- Hierachical Custom post types permalinks not working
- Better way to enforce category hierarchy in post_categories_metabox?
- Taxonomy/category hierarchy lost when editing posts [closed]
- How to enable hierarchical permalinks for hierarchical taxonomies
- Categories’ hierarchy in URL
- Custom Taxonomy Only Showing Top Level Terms in Admin?
- Does the ‘WordPress Order’ feature, within the WordPress Dashboard, have any impact on site architecture?
- Easy way to process search results before displaying
- How to check if last uri segment is a custom post type or taxonomy term?
- Custom permalinks – post type – hierarchical taxonomy’s
- URL Design for Sub-Posts?
- How to set hierarchical terms to a post using wp_set_object_terms
- How to Create Hierarchical Directory for Nation Wide Mental Health Services
- Hierarchical display of custom taxonomy
- Getting taxonomy terms used by custom post type
- Custom Taxonomies: Multiple Hierarchical Permailnks For A Single Post + Prev/Next Links
- custom post type index page
- How to get parents of custom taxonomy, as what get_category_parents() do?
- Hierarchical or Non-hierarchical Custom Post Type in Real World Example
- Detect if 1st, 2nd or 3rd level custom page?
- Custom post type routing with hierarchy
- Taxonomies: display hierarchical parent list
- Show hierarchical relationship between to custom post types on admin list
- Custom post type hierarchical permalinks not behaving as expected for parent/child pages
- Custom Post Type with two hierarchical Custom Taxonomies: strategy to generate best permalink structure
- How can I get an tag to wrap each ancestor that gets outputted in this condition?
- Category tree is flattened inside admin upon saving
- get_pages — parent vs child_of?
- Categories vs. Page Site Organization
- How to output hierarchical taxonomy path, with only the deepest term assigned?
- Twenty Fifteen: Adjacent posts by menu_order [duplicate]
- How to display related posts by subcategory and not parent category
- Why are wordpress posts not hierarchical?
- Multi-level page hierarchy
- post_row_actions not working for hierarchical post type
- Custom Post Type / Two level deep taxonomy (cat. and subcat.) uri problem (error 404)
- Determine page content based on page parent
- Use a hierarchical custom post type for a main blog and subblogs?
- Register a pre defined tree of taxonomies
- How do you cope with the task of adding hierarchy to the navigation menu?
- how to get the categories for a single product in a hierarchical way
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- How to categorize posts under Category 1 and Category 2 which are separate lists of categories, and display them as separate lists in widgets
- Rewrites/query for multiple hierarchical custom post types
- Give a page priority over a category that has the same name?
- Custom while loop for hierarchical display of a taxonomy
- Using custom taxonomies to display hierarchical URLs?
- How to get Next/previous_post_link to go through articles in top parent category
- Taxonomy Drill-Down / Plugin Help – hierarchical queries within plugin?
- Different layout on second page
- WordPress list categories dropdown with parent-child relation and child under it’s parent
- tax_query: Don’t show posts with parent term when they have a corresponding child term applied
- Templates for hierarchical custom post type
- Display a specific hierarchical level of a specific custom taxonomy
- custom hierarchical taxonomy and custom post type list contains surplus posts
- Query all post types but limit to parents
- Delete child post and attachment links to parent post
- How to load several hierarchical categories from functions.php
- Use an archive as the parent of a page?
- Check is category parent with ids from the childs – get_term_children
- Posts not listing out sub category in hierarchy
- list all child categories that apply to current post even if those cats are empty?
- Converting a hierarchy of off-site web-links to Word-Press
- Tags hierarchical
- Rewrite Post URL so it is constructed from parent post url & child post url
- Setting Custom Post Type Parents/Hierarchies
- Custom taxonomy terms hierarchical navigation
- Having hierarchies inside WordPress custom post type
- Custom Post Type parent/child relationship rewrite rules for permalinks
- hierarchical Custom post type child permalink not found
- Most efficient way of showing children posts?
- Different template for subcategories
- Display a Custom Post Type within another with hierarchically slug
- Show full category tree for a year with all post titles?
- Custom Post Type Child Pages
- Determine if Term has Grandparent/Great-Grandparent
- Cross post type parent page added parent page to permalink but give 404
- General question about Parent and Child Post type relationships
- Hierarchy between post types
- Getting grandchildren of a post with a specified custom taxonomy?
- A simple script/plugin to display specific page upon hierarchy of selections
- Best Way To Structure 3 Tiered Site
- Display Parent and child taxonomies in seperate drop downs [duplicate]
- How can I set the first link in my nav menu to simply be a drop-down to some other pages
- Rewriting hierarchical post type
- More than one Hierarchical Taxonomy and SEO
- How do I assign the post parent?
- How to add a regular page under a custom post type?