It’s possible to have them share the same slug, but you need to manually resolve conflicts yourself. You have to check if the end of the requested URL is an existing term, and reset the query vars accordingly if it’s not found:
function wpd_post_request_filter( $request ){
if( array_key_exists( 'category_name' , $request )
&& ! get_term_by( 'slug', basename( $request['category_name'] ), 'category' ) ){
$request['name'] = basename( $request['category_name'] );
$request['post_type'] = 'post';
unset( $request['category_name'] );
}
return $request;
}
add_filter( 'request', 'wpd_post_request_filter' );
The obvious downsides to this are an extra trip to the database for every post or category view, and the inability to have a category slug that matches a post slug.
Related Posts:
- Why is “/page/2/” not working?
- How does WordPress handle permalinks?
- Get page permalink without wpurl
- Can I use REST-API on plain permalink format?
- How to change ‘with_front” key from an existing custom post type?
- Why would Numeric permalinks work, but %postname% won’t?
- Passing variables through permalink structure
- Make post slug have priority over category slug
- Adding anchor to paginate_links + Safari anchor bug
- How to stop permalink redirects for a particular slug
- Why does WP not use relative links when linking pages?
- What is the action or filter for changing permalink in Edit Post/Page?
- WordPress Links Not Working After Migration
- Migrating WordPress blog to New Webhosts, something is adding a # and gibberish
- How to get wordpress link to fully evaluate when coming from facebook
- Is using %postname% for permalinks really that bad for performance?
- Adding File Extensions to Attachment Page Permalinks
- How to tranform Headlines into linkable permalinks?
- Best way to add internal link in widget
- Changing search URL to something other than “search”
- Changes to .htaccess not updating the file (old rules still take effect)
- article pages not displaying on local instance of wordpress site
- breadcrumbs & rel=”nofollow”
- Use Regular Expression to get tag from permalink url during wp_rewrite in generate_rewrite_rules
- Create unique alphanumeric ID on wp_insert_post
- Programatically changing post’s permalink when identical post type is published
- Permalinks not working with Vagrant
- Possible to remove taxonomy from permalink if uncategorized?
- Is there a link parameter that will show me all my published pages?
- Add prefix to page URL based on the page template
- Files rendering adding “.x95527” before file extension [closed]
- How to eliminate permalink prefix in WordPress Multisite
- wp not making CPT permalink / slugs unique
- Mirror content based on URL slug
- How to change hierarchical page permalinks to be flat
- Permalink structure with $_SESSION variables
- Hierarchy of Subcategories on Permalink (bug?)
- Strange Anchor Tag Behavior (in-page links work, external pages do not) [closed]
- WordPress 3.1 .htaccess contents keep dissappearing?
- Permalink in WordPress loop outputs for each new line
- Freeze child page URLs so parent permalink changes don’t give 404s?
- New custom PHP pages are getting 404s
- How to test custom rewrite rules /permalinks?
- Add a filter to get_comments_link()
- How Do I get the author’s page id?
- Adding a prefix to the blog, but only the blog
- Show category name in the post URL only for specific categories
- Old site posts broken after domain update
- After cloning WP do a subdirectory, I can’t access it
- Moved site, Old links in pages still pointing to old host
- help to remove last trailing slash using add_rewrite_rule
- change WordPress permalinks and redirect new urls 301
- Protect Post Permalink From Copy
- Change permalink to attachment
- WordPress Page Not Found if Permalink Settings is Postname
- Main blog page works but title says Page not found
- How to translate “Permanent link to” text
- WordPress Permalink Redirect 301
- problem with pagination in custom permalinks
- WordPress permalink change causes all incoming links to give 404 errors
- Problems with permalinks (.htaccess not working)
- WP as a CMS menu
- Subdomains pointing to a permalink URL
- Change author permalink using htaccess?
- /%post_name%/ or /%postname%/ in Permalinks?
- corrupted URLs – can’t leave starting page
- how can i change the permanent from permalinks (wordpress)
- A dash can replace a period in a link, how to fix it
- Remove character from permalink
- Problem with two WP installation on root and subfolder
- WordPress image title attribute becomes permalink? [duplicate]
- Nested permalink without dummy parent page
- home page slug editor missing from WordPress
- Custom Taxonomy rewrite rule causes 404 error on page or single post depending on if it’s set to “True” or “False”
- followup to: Page begins with number, WordPress adds 2
- Pages with parent pages giving 404 errors
- WordPress and Woocommerce Chinese Permalink
- redirect any category in URL to the ID and post-name only – hundreds of pages affected
- permalink as content
- WordPress website redirecting to old domain if I not specificy / at the end
- Moved WordPress to other folder (Windows) WAMP = 403 Forbidden
- LetsEncrypt WordPress on the Raspberry Pi – Nice url’s give 404 with https, http works
- On IIS, stop WordPress from resaving my web.config file when I enter the Permalinks config page
- Rewrite single template permalink?
- changing permalink gives 404 error for old links
- single.php being ignored, going straight to attachment.php
- WordPress URL Problems After Change it
- Get permalink of a post without using WordPress functions
- Automatically prepending ‘#’ to slug in child page permalinks
- Possible to hide parts of the slug from get_template_directory_uri and bloginfo(‘template_directory’)
- Permalink broken for pages after adding rewrite rule
- Tag URLs load a single post
- Pretty Permalinks cause site to crash on main domain
- [Plugin leenk.me]modify get_the_title
- Performance and styles not working fine after changing permalink structure
- Are custom page templates being used to get this permalink structure
- get_posts displaying wrong permalink for “continue reading” link
- Getting the terms from “Beautiful Taxonomy Filters” Results ot Integrate into “Ajax Load More”
- Page permalinks are http but show up as https?
- Permalinks get lost periodically