My Permalinks are the std %postname%. I have several custom post types, eg. 'docs'.

function docs_init() {
// create a new taxonomy
    'label' => __( 'Documentation_Tax' ),
    'sort' => true,
    'args' => array( 'orderby' => 'term_order' ),
    'rewrite' => array( 'slug' => 'docs' )

I would like to be able to have duplicate slugs. Eg. I'd like to have a general Page with the slug 'MyPage' and then a Docs post type also with the slug 'MyPage'. The goal is to have users be able to do this:

URL: mysite.com/mypage ---- general Page

URL: mysite.com/docs/mypage ---- posttype Docs

...and this does not work. If the user types /docs/mypage, the browser redirects to /mypage ...even though in the post editor it shows that /docs/mypage is the URL.

I thought that since 'with_front' defaults to true, WordPress would distinguish between the two slugs by assigning the 'front' (ie. the post type.)

How can I get what I want... or is it simply mandatory to have unique slugs?




Simple answer is that you can't as far as the default wordpress installation goes. It's a must to have unique slugs.

You can however mess with the Rewrite API with some custom code to hack your way around this & there aren't any plugins(AFAIK) to help you on your way. So it's definitely a lot easier to just force your users to unique slugs

  • 1
    Curses. OK, what I don't get is that WP -seems- to -want- to be able to do what I ask. Eg. if I have a custom post 'docs' of slug test, the URL is /docs/test. Fine. But if I then create a Page with the slug 'test', if you type in /docs/test it ignores the 'docs' and redirects to just /test... so it 'knows' to prepend the posttype, but then chooses to ignore it.
    – jchwebdev
    Nov 8 '12 at 21:50
  • wordpress always try to match the url to inbuilt mechanisms first & then, if it doesn't find a match, it tries the custom things. The code that creates the url works completely seperate from the one that reads the url. I know it's not a good way & confuses a lot of people but that's how wordpress works. There have been tickets in wordpress trac to address this issue but unfortunately, not implemented Nov 9 '12 at 8:54
  • Can you suggest where in the rewrite engine to look for the code that -reads- the URL. Most of the plug-ins and posts I have researched are concerned re-writing incoming URLs for SEO... ie. the exact opposite of what I want to do. Just need a starting place to search. The WP docs on the rewrite API are pretty thin.
    – jchwebdev
    Nov 9 '12 at 17:48
  • "wp-includes/rewrite.php", class WP_Rewrite, function rewrite_rules. This function is in charge of converting a permalink url to the normal url Nov 9 '12 at 19:02
  • I had this problem and I had to wind up doing two taxonomies, but this was due to template hierarchy. Oct 1 '13 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.