Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it true that slugs must always be unique, regardless of the rest of the url, or if it's used by different post-types or taxonomies?

For example, is it possible to have both of these urls?

mysite.com/industry/biotech/report/
mysite.com/industry/retail/report/

Thanks, todd

share|improve this question
add comment

2 Answers

In wp_unique_term_slug():

The $slug has to be unique global to every taxonomy, meaning that one taxonomy term can’t have a matching slug with another taxonomy term. Each slug has to be globally unique for every taxonomy.

In wp_unique_post_slug():

@param string $post_status no uniqueness checks are made if the post is still draft or pending […]

Attachment slugs must be unique across all types. […]

Page slugs must be unique within their own trees. Pages are in a separate namespace than posts so page slugs are allowed to overlap post slugs. […]

Post slugs must be unique across all posts […]

WordPress modifies post slugs to enforce uniqueness, if necessary, when a post's status changes to publish or when Pages are moved among Page trees, so if you want to avoid that, it's best to just try to write unique slugs yourself.

Unconfirmed, but I seem to remember:

  • WordPress sometimes increments slugs (hello-world-2) and sometimes truncates them (hello-worl !) to enforce uniqueness
  • You have to empty the Trash to make the slugs of Trashed posts available again.
share|improve this answer
add comment

Yes, post slugs must be unique, regardless of the post type; it's enforced at the database level. Same for term slugs.

I don't think they have to be unique between them. I.e. you can have a 'report' post and a 'report' term.

To obtain the kind of permalinks in your example, though, you probably don't need to create multiple posts with the same slug. You just need a custom rewrite rule that ends with /report/ and maps to something else.

share|improve this answer
    
Ah thanks! I'm not really familiar with custom rewrite rules in wp yet, so hadn't even thought of that approach. I'll look into it.. but just wondering if there's a quick answer to how to accomplish those urls with custom rewrite rules? –  tzeldin88 Dec 2 '11 at 6:53
    
I disagree. I'm looking at a post and a page right now with the same slug...no issues. The post has a date/post-slug and the page just has a /post-slug permalink. –  AlxVallejo Feb 6 '12 at 14:06
    
Slugs don't have to be unique depending on the hierarchy involved but it's a really, really good idea to make them unique. –  JCL1178 May 10 '12 at 20:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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