To handle the extra URL segment you need to add another rewrite rule similar to the one generated by add_permastruct
, but with an extra capture group and slash for the additional level of terms:
add_rewrite_rule(
'book/([^/]+)/([^/]+)/([^/]+)-blah-blah-blah?(:/([0-9]+))?/?$',
'index.php?post_type=book&name=$matches[3]',
'top'
);
Also, as I mentioned in my comment, the query var and slug author
are already in use by core, you should probably change those.
Also in your post_type_link
function, you should check if terms/parent terms exist before trying to access their properties, which will produce warnings with debugging enabled.
Related Posts:
- Custom Post Type Permalink / Rewrite not working immediately
- WordPress Rewrite Rules for Custom Post Type and Taxonomy
- Permalink rewrite 404 conflict- WordPress Taxonomies/ CPT
- How to modify URL structures in custom post types and taxonomies or terms
- Help with a TV series Rewrite structure
- Permalink rewrite with custom post type and custom taxonomy
- How to check if last uri segment is a custom post type or taxonomy term?
- WP Rewrite Rules – Custom post type & taxonomy
- Remove base slug in CPT & CT, use CT in permalink
- Custom Permalink Tag breaks Pagination
- Custom Permalink for Taxonimie and Custom Post Type
- Add hierarchical taxonomy to permalink for custom post type
- Permalink Structure CPT With Custom Taxonomy Fails
- Customize Custom Post Type URL
- Custom Permalinks with CPT and Hierarchical Taxonomies
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- WordPress custom permalink and archive link for custom post type
- Template hierarchy changes when custom post-type permalink leverages custom taxonomy
- Associate custom CPT with another CPT’s taxonomy and rewrite permalinks
- Parent cpt/child custom post type URL permalink relationship
- Adding rewrite rules to Custom Post-type mixed with Taxonomy
- 404 Error On Custom Taxonomy Pages 2, 3, etc
- Two Permalinks with one Taxonomy (custom taxonomy) and (custom post type -> custom taxonomy)
- Custom post types, taxonomies, and permalinks
- Permalinks: custom post type -> custom taxonomy -> post
- Mixing custom post type and taxonomy rewrite structures?
- How do I append multiple taxonomies to the URL?
- Custom rewrite rules for archive page and single post
- Custom Post type & Taxonomy URL structure
- Custom post type 404s with rewriting even after resetting permalinks
- Rewrite rule for Custom post type Monthly and Yearly archive
- Archive page with multiple taxonomies rewrite
- Taxonomy archives based on Custom Post Type
- Custom permalinks – post type – hierarchical taxonomy’s
- Permalinks for CPT breaks permalinks to pages
- Page to display an archive of taxonomies
- How to create a permalink for custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name
- How to show custom taxonomy in the permalink?
- Date-based permalinks for Custom Post Type, and custom taxonomy permalinks
- WordPress rewrite my URL when i use pagination
- Custom Taxonomy breaking pages permalinks
- Permalinks for custom post-types within custom taxonomies not found
- Custom post types and permalinks
- Custom Post Types and independent Categories – complex Taxonomy
- How can achieve this permalink perfectly? domain.com/%category%/%post-name%
- custom-taxonomy/post_name instead of the default post_type/post_name
- How do I change the custom taxonomy slug to be the same as the custom post type slug?
- Permalinks /country/city/cpt/postname/
- Seamless permalinks between Custom Taxonomy and Custom Posts
- Custom post type and custom taxonomy with the same slug using the file page taxonomy only as directory
- WP Rewrite Rule Issue while using Custom post type & taxonomy
- How to change permalink to include custom post type
- Make custom post types and pages place nice, re: rewrite
- Get url.com/post_type/taxonomy/term work!
- set permalink for CPT
- Different rewrite rules for taxonomies and cp in multisite?
- How to add custom taxonomy in custom post type permalink?
- Permalink problems with custom post type and custom taxonomy
- SEO Concerns With Rewrite Rules
- Route subpage to Custom Post Type
- Custom Post Type Advanced Slug
- Rewrite permalink for multiple post types (CPT) with taxonomy term
- Ideas on how to organize a project [closed]
- Custom Post Type with modified permalink structure results in 404
- Modifying rewrite rules to use /category//
- Change permalinks for custom post type based on taxonomy term
- Custom post type category permalinks and archive pages
- Safe to throw 404 error in request filter?
- Is there a way to use ‘publicly_queryable’ => false only on specific taxonomy term?
- How to prefix custom post type URL with custom post taxonomy term?
- Category permalinks don’t work even after flushing
- Custom post type single page returning 404 error when sharing archive url with custom taxonomy
- Changing permalink of default Post with custom post
- Custom Taxonomy Archive generates 404
- Custom post type single with custom URL structure
- How to create a permalink structure with custom taxonomies and custom post types
- Pagination not working (page/2 retunring 404 page)
- How to build overlapping custom post_type and taxonomy rewrites without conflicts?
- Change the url of a custom post type to include taxonomy
- Permalinks for a custom post type – with a page template (custom query) and taxonomy archive
- Post Custom & Taxonomy 404 error
- WordPress custom post type rewrite rule matches all pages returning 404
- page not found for example.com/custom-post-name
- Multiple archives for cpt, taxonomies, terms
- Same permalink structure for all post types?
- How to add base permalink to custom posts?
- Hierarchical taxonomy in permalink structure
- Rewrite for custom type and custom taxonomy
- Why won’t this rewrite rule work?
- taxonomy term names in custom post type permalink structure
- Change Taxonomy Permalinks
- Category / Custom Post Type permalink issue
- Custom post type permalink structure
- Remove slug from Custom Category Permalink + dual-category permalinks
- How to have a dynamic slug and rendering the archive-{post_type}.php?
- Add /blog to the “post” post type url
- Url rewrite with custom post type and taxonomy
- Same slug for Custom Taxonomy archive and CPT archive – Rewrite rule not working
- What is the best way to relate different custom post types?
- Modify permalink of CPT archive to support two taxonomies