Must slugs be unique?

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?

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

Thanks,
todd

Related posts

Leave a Reply

3 comments

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

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