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 create a permalink structure with custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name
- How to show a hierarchical terms list?
- The Difference Between Hierarchical and Non-Hierarchical Taxonomies?
- get_posts assigned to a specific custom taxonomy term, and not the term’s children
- How to set parent-child relationship between differents custom post types
- Get the the top-level parent of a custom taxonomy term
- How can I allow commas in tag names?
- Integrating a custom post type into a page hierarchy
- Nested custom post types with permalinks
- Custom taxonomy, get_the_terms, listing in order of parent > child
- Change custom post type to hierarchical after being registered
- How to Check if a Page Exists by URL?
- How to display non-hierarchical taxonomy as terms with checkboxes?
- Get top level page parent title
- How To Limit Hierarchical Pages Depth (For Custom Post Types) To Children Only
- Determine Term depth
- page title, parent tilte and grand parent title
- How to add a custom metabox to the Menu Management admin screen?
- What is the best page ordering plugin that works well with WPML? [closed]
- Display a list of child posts on parent posts of a custom post type
- Custom Post Type as Page parent
- Show current navigation path from menu
- How to handle a hierarchy with custom post types
- WordPress admin screen very slow / timing out when editing or adding a new page/custom post
- Different template for subcategories
- Custom Taxonomy Tree view
- Can I have Post Types under other Post Types in Admin menu?
- 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
- Disable block from editor based on post type
- Get taxonomy name of current post
- Categories’ hierarchy in URL
- Determine if Term has Grandparent/Great-Grandparent
- Custom Taxonomy Relationship (ex: plant classification)
- Custom Taxonomy Only Showing Top Level Terms in Admin?
- Child pages on hierarchical Custom Post Types 404s
- How can I combine posts of different types in one hierarchy?
- Does the ‘WordPress Order’ feature, within the WordPress Dashboard, have any impact on site architecture?
- Easy way to process search results before displaying
- Custom Post Type ‘hierarchical’ Help!
- Is there any difference between post in child term and child & parent terms?
- How to check if last uri segment is a custom post type or taxonomy term?
- How to only show posts on last child category
- Custom permalinks – post type – hierarchical taxonomy’s
- How to show term-specific post list, without posts associated with child terms?
- How to fix a double slash in custom permalinks with hierarchical taxonomy’s?
- How to show only parents subpages of current page item in vertical menu?
- Permalinks for WooCommerce Categories and Subcategories
- URL Design for Sub-Posts?
- How to include parent terms in hierarchical taxonomy URLs?
- How to query for posts (in hierarchical custom post type) that have children?
- Get parent page/menu id of current post
- How to set hierarchical terms to a post using wp_set_object_terms
- Help building array hierarchically with taxonomies (to get posts)
- 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
- Categories lose hierarchy order once assigned to post
- how to automatically generate hierarchical menus from hierarchy of pages?
- wp_list_pages doesn’t work in hierarchical custom post type
- custom post type index page
- Post type hierarchy
- 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?
- Populating dropdown menu with hierarchical taxonomies
- Hierarchical Custom Post Types or Similar
- Custom post type routing with hierarchy
- Taxonomies: display hierarchical parent list
- Parent / Child formatting in a list of post of a custom post type
- Show hierarchical relationship between to custom post types on admin list
- Custom post type hierarchical permalinks not behaving as expected for parent/child pages
- How to create a permalink structure with custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name
- Add Product categories to WordPress menu without losing hierarchy
- How to Combine Two Custom Post Types into Single Permalink Structure
- Custom Posts Hierarchy? (State/City/Restaurant)
- Custom Post Type with two hierarchical Custom Taxonomies: strategy to generate best permalink structure
- Automatically populate a hierarchical taxonomy from a custom field
- How can I get an tag to wrap each ancestor that gets outputted in this condition?
- Hierarchical Custom Posts – Highlighting Current Post in Sub-Menu
- how to get the categories for a single post in a hierarchical way
- Category tree is flattened inside admin upon saving
- Remove base slug in permalinks of hierarchical custom post type
- get_pages — parent vs child_of?
- Modifying Custom Post Type after registration (will it affect content?)
- Hierarchical Custom Post Types – Show only parent on tax archive?
- Display hierarchical subterms of custom taxonomy based on depth
- Categories vs. Page Site Organization