you can try with this plugin (or see its code)
https://wordpress.org/plugins/wp-better-permalinks/
It allows you change the custom friendly permalinks structure to Custom Post Type > Taxonomy > Post and Custom Post Type > Taxonomy instead of default WordPress structure.
it Provides different permalinks structure pattern:
Custom Post Type > Single Term (or Term tree) > Post
Custom Post Type > Post (when no term is selected)
Custom Post Type > Single Term (or Term tree)
It helped me a lot with this issue…
Related Posts:
- Mixing custom post type and taxonomy rewrite structures?
- Rewriting a custom-post-type permalink with taxonomy term?
- WordPress Rewrite Rules for Custom Post Type and Taxonomy
- How to modify URL structures in custom post types and taxonomies or terms
- Create permalink structure for one taxonomy archive per custom post type
- Custom permalinks
- Permalink rewrite with custom post type and custom taxonomy
- Custom Permalinks for Custom Post Types and Taxonomies
- Including two taxonomies in a permalink structure
- WP Rewrite Rules – Custom post type & taxonomy
- Remove base slug in CPT & CT, use CT in permalink
- How to rewrite custom post type URL for multiple depths instead of one specific depth
- Custom post type category, taxonomy and URL rewrite problem
- Permalink Structure problem with cpt and custom taxonomy
- Custom Permalink Tag breaks Pagination
- Custom Permalink for Taxonimie and Custom Post Type
- multiple url slug for single custom post type
- Custom Post Type and Custom Taxonomy Permalinks
- Permalink Structure CPT With Custom Taxonomy Fails
- Change Permalink Structure for Tag.php template
- Custom taxonomy in URL showing 404
- Adding custom post category slug in permalink causes 404 error for pages and posts
- How Can I Change the Custom Post Type Slug to the Taxonomy Slug in the URL?
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- Customize Custom Post Type URL
- Custom Permalink to remove category word , keeping posts permalink with date?
- Custom Permalinks with CPT and Hierarchical Taxonomies
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- Custom taxonomy returns 404
- CPT’s with landing page instead of archive – Url Rewrite?
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- Custom permalink with child taxonomy terms
- Best way to specify “article type” in URL
- Custom Post Type Advanced Slug
- WordPress custom permalink and archive link for custom post type
- Custom Permalink For Custom Post Type – Working Fine But Broken For Pagination
- Error 404 change permalink term custom term taxonomy
- Changing CPT permalink
- Pretty Permalinks with CTP and Taxonomies / Hierarchical
- Customise Permalink Structure For Custom Post Types
- % encoded URL giving 404 error in WordPress
- Parent cpt/child custom post type URL permalink relationship
- Custom Post Type Permalink / Rewrite not working immediately
- Changing the URL Structure of a Paginated Custom Post
- Templates for Custom Post Types and Custom Taxonomies
- Understanding Permalinks on Custom Post Types
- Issues when rewrite rules collide?
- Custom post type permalink changing itself every other change
- Add links to post categories and taxonomies in wysiwyg link modal?
- Removing parent slug from URL on custom post type
- Maintaining WP_Query Relation Among CPT, Custom Taxonomy, Permalinks- CPT UI
- Rewrite on custom post type permalink not working?
- Custom Post Type: How to display all of same taxonomy?
- Remove POST_TYPE from custom post type permalink
- Custom Post Type/ Taxonomy URL rewrite
- Remove “-2” from a Toolset Types URL with the same post name
- Permalinks for Taxonomy and Custom Post Type
- Programmatically adding posts
- Pretty URLs for Custom Post Type & Custom Taxonomy with Duplicate Slugs on WPML
- Custom post types, taxonomies, and permalinks
- How to specify URLS for custom posts & taxonomies
- Permalinks not working for custom taxonomy on custom post type
- Custom Post Type permalink shows wrong page: homepage/index.php
- Rewrite rules for custom posts types
- Custom Post Types, URL rewrite on multiple CPTs
- Custom post type url with category
- Custom post type as home page with custom url
- How to rewrite url for any specific taxonomy?
- Custom post URL 404 error
- URL rewrite add author as base
- Set a CPT slug as a base name for all the taxonomies
- Custom taxonomy rewrite with query var returns %2F in URL
- Remove slug in URL custom post type
- Hierarchical permalinks for custom post type and taxonomy
- Template files for Custom Post Type and Taxonomy
- How to have permalink like domain.com/term/postname?
- How to filter a custom post type by custom taxonomy without 404
- Post type Permalink
- How to rewrite the post slug of a custom post type post
- Custom Post Type nest under a normal WordPress Page
- Is it possible to have hierarchical taxonomy and hierarchical custom post types in one permalink?
- Custom category URL not displaying posts
- Use a different URL path / permalink for CPT
- Duplicate slug/permalink issue while adding same post name
- Remove custom permalink base from CPT custom category and custom tags
- How to handle this wordpress custom post type rewrite problem?
- Custom URL for Custom Post Type & Custom Taxonomy Term
- Custom taxanomy and custom post type – pagination leads to 404
- Flush rewrite rules when new cpt is registred
- Pretty permalink structure with multiple (AND OR) taxonomies
- How can I add a “fake” parent into the permalink?
- Add category slug as class attribute in a link array
- URL Rewrite Adjustment for Custom Post Type causes template to revert to index.php
- WordPress Custom Permalink Structure with Custom Post Type and Taxonomies
- Add taxonomy to custom post type archive
- Custom Post Type – Rewrite slug [duplicate]
- Rewrite rules for using the same base slug for multiple content types
- Menu Structure and URL structure, with Pages and Post-Type-Posts
- Custom Post Type urls not working