1

Is there an easy way to have a permalink structure for Custom Post types that looks like this?

mysite.com/post-type/ - Listing Page for Post Type

mysite.com/post-type/taxonomy/ - Category/Taxonomy Listing Page

mysite.com/post-type/post-name/ - Single Page for Post Type

I have tried the plugin WP Better Permalinks, but it adds a taxonomy to the URL when viewing the single page, which I do not want at all.

Similarly, the inbuilt WordPress permalinks add 'categories', or the name of your custom taxonomy to the URL. Again, not what I want.

1

1 Answer 1

2

The default behaviour of mysite.com/post-type/ and mysite.com/post-type/post-name/ is what you want it to be, so you don't need to do anything special there.

To have mysite.com/post-type/taxonomy/ as the URL for the taxonomy archive, all you need to do is use 'post-type/taxonomy' as the rewrite => slug argument when registering the taxonomy.

4
  • How smart is WP with checking "same" permalink structures? If example.com/post-type/foo is requested, but foo is not a taxonomy, will it check for posts or give a 404? (and vice versa)
    – kero
    May 22, 2018 at 6:03
  • It's not smart at all. When you register a taxonomy or post type it creates a 'rewrite rule'. Whenever you go to a URL on your WordPress site WordPress will go through these rules and see if the current URL matches. If it matches it will do whatever that rule says to do. If that fails for some reason it won't try the next rule or anything like that, it will just 404. May 22, 2018 at 8:10
  • Hey, thanks for the answer! I actually asked my question wrong, though, haha. When I said mysite.com/post-type/taxonomy/ I meant mysite.com/post-type/term/. An ideas? I can make a new question, or edit the original if that's more appropriate.
    – KillahB
    May 23, 2018 at 14:53
  • Try searching first, variations on that question are common. It will probably involve creating rewrite rules manually and requests will require extra queries to determine whether to load a term or a post, since the permalink structure is the same. May 23, 2018 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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