I dont know how I missed out on that while looking for aproaches, but I have a working solution now based on this answer.
I modified it to check for slashes in $query->request
, if there is none I first look for my custom post type (get_posts()
with'slug' => $query->request
). If no post is found I do the same for the taxonomy (get_terms()
).
If there is one slash, I explode the $query->request
to $parts
and look for a custom post with 'slug' => $parts[1]
and a tax_query array for the custom taxonomy.
Whenever something is found I do something like:
$new_query = array(
'post_type' => 'my_post_type',
'name' => $name
);
$query->query_vars = $new_query;
If nothing is found the query is untouched, and in the end I just return $query;
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
- Parent & Child Taxonomy slugs in custom post permalink
- Customize Custom Post Type URL
- Custom taxonomy rewrite with query var returns %2F in 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)
- How to create a permalink structure with custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name
- Shouldn’t this be easy?! Custom post type/custom taxonomy permalink
- Best way to flush_rewrite_rules for custom post type, in a mu-plugins plugin?
- Custom Post type & Taxonomy URL structure
- Multiple post types – share same ReWrite slug?
- Combining Multiple Taxonomies in one URL
- Why does a custom post type need the ”hierarchical’ args setting?
- Modify custom post type rewrite rules in a separate function
- array_pop() expects array, boolean given for $event_type_term ->slug
- Using %postname% tag with a Custom Permastruct creates 400 Bad Request Errors from the server
- custom post type permalinks with category and tags
- Custom Post Type with Nested Taxonomy and Template Files
- Semantic URL Custom Post Type and Taxonomies permalinks
- How to rewrite custom post type URL for multiple depths instead of one specific depth
- Include taxonomy slug in url?
- Custom permalink – append taxonomy name and term name at the end of permalink
- custom post type and custom taxonomy url conflict
- How much control do we have over CPT rewrite slugs? Can I create a “root” page for my CPT with out the page path, and then have paths for other pages?
- custom permalinks based on taxonomies for custom post type
- Custom taxonomy in URL showing 404
- 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
- create a subcatagory for a custom post type and out put url as posttype/subcategory/item
- How can achieve this permalink perfectly? domain.com/%category%/%post-name%
- custom-taxonomy/post_name instead of the default post_type/post_name
- Show custom post archive when custom post not specified
- Show custom post type relationships by taxonomy
- WP Rewrite Rule Issue while using Custom post type & taxonomy
- Permalinks: custom post type -> custom taxonomy -> post
- Custom post type permalink tag 404
- How to get list of taxonomy slugs ordered parents>childs?
- Get url.com/post_type/taxonomy/term work!
- Template for custom post type when taxonomy is in the URL
- Custom Post Type posts, conflict with posts after add_rewrite_rule to top
- Combine multiple CPT names to create valid permalinks
- SEO Concerns With Rewrite Rules
- How to rewrite custom taxonomy term archive to use THE SAME SLUG/front as CPT
- 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
- Subpages Permalinks Issues
- Safe to throw 404 error in request filter?
- Multiple permalinks for a single post with multiple taxonomies
- rewrite rules hierarchical
- Rewrite URL for CPT to domain/post-name/post-id
- 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?
- How do you create pillar content pages?
- Custom permalink structure for custom post types including multiple taxonomy
- Custom post type single page returning 404 error when sharing archive url with custom taxonomy
- Custom post type single with custom URL structure
- Customise Permalink Structure For Custom Post Types
- Pagination not working (page/2 retunring 404 page)
- How to build overlapping custom post_type and taxonomy rewrites without conflicts?
- Two CPT: one is using part of the custom rewrite slug from the other
- 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
- how to use two permalinks for one custom post type based on categories
- WordPress custom post type rewrite rule matches all pages returning 404
- Multiple archives for cpt, taxonomies, terms
- How to add base permalink to custom posts?
- Permalinks when using Custom Post Type with static page for archive
- How to change permalinks to taxonomy and post type’s posts
- taxonomy term names in custom post type permalink structure
- How to make nested custom post type slugs work
- Custom Post Type Permalinks Problem
- Change Taxonomy Permalinks
- 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
- Different CPT permalink base on taxonomy
- Hide custom post type slug url from search engine [closed]
- Is it possible for post and custom post type to share a category base slug?