7

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

3 Answers 3

7

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.
2

I know this is an old post, but I think there is wrong information here. I was having conflicts with slugs between different custom post types and taxonomies and decided to do some reading about it to understand it better.

I am using WordPress 4.2.2, and I am able to create different posts types with the same slug. Apparently this is a known issue being tracked. However, it is unclear what the rules are for slug uniqueness.

https://core.trac.wordpress.org/ticket/13459

What makes the most sense to me is that post slugs need to be unique among post types (pages, posts, CPTs) and taxonomy slugs need to be unique among taxonomies. But currently on versions 4.2.2 these do not apply. I guess I will just have to work with it not knowing.

1

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.

3
  • 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, 2011 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, 2012 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, 2012 at 20:56

Your Answer

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

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