Opened 19 months ago

Last modified 6 months ago

#18962 new enhancement

Allow duplicate slugs for different content

Reported by: maorb Owned by:
Priority: normal Milestone: Future Release
Component: Rewrite Rules Version:
Severity: normal Keywords: needs-unit-tests
Cc: maor@…, scribu, mbox@…, mike.schroder@…, thirstcard

Description

Currently, the slug of a post (or any other CPT) must be unique.
If a content is being created and an already existing slug is being assigned to it - WP will add a number for identification (i.e. about-2 etc).

That means, that if one has content from different content types, or in different categories (taxonomies), it still cannot have same slug.

The issue might be very disturbing when working in a multi lingual site (i.e using WPML or any other plugin for that).
Suppose there is an about page - www.mysite.com/about.
This is in the main language of the site.
Than a translation to that content page is being added, let's say it is translation to English.
You would expect url something like www.mysite.com/en/about, but the slug is being changed to about-2, so the url of the about page in English becomes www.mysite.com/en/about-2.
For a site with 10 languages, let's say, it will end with urls like site.com/lang/about-10 etc.. and this is not looking good and may confuse.

As a cms, WP should let the admin/developer/operator - to have same slugs for different content types, or even in the same content type. The $post->ID is the unique identifier of a content, why should be also the slug?

Change History (12)

Hmm, I thought you could have the same slug across multiple most types, but I've just tested it and evidently you can't. Maybe this is a regression?

The only case where you can have the same slug for multiple posts is on different levels within hierarchical post types. Eg. example.com/hello and example.com/sub-page/hello. If this is allowed then it's odd that the same slug isn't allowed across post types.

I've built a plugin for WPML which allows duplicate slugs for the same content across languages. If you're interested email me at my username at gmail and I'll send it over.

And just to address your core point, slugs have to remain unique within their post type for obvious reasons, so they are uniquely identifiable at their URL.

Version 0, edited 19 months ago by johnbillion (next)

comment:2 follow-up: ↓ 3   azaozz19 months ago

How about when permalinks are set only to %postname%?

comment:3 in reply to: ↑ 2   scribu19 months ago

  • Cc scribu added

You can use the same slug in multiple hierarchical post types, but only for a page that is NOT top-level, AND NOT the same level w/in the same post type.

The function wp_unique_post_slug() disallows identical slugs for the same post_parent. and since all top-level pages of heirarchical pages have a [post_parent] => 0, they can't have the same slug.

Not sure if that's intentional, but it is the result. Been testing it lately, here's the URLs possible:

/test/

/test/test/

/test/test-2/

/test/test/test/

/cpt-name/test-2/

/cpt-name/test-2/test/

All the above "test" slugs have a different [post_parent], so the identical slug is allowed. All the above "test-2" slugs had the same parent as another "test" slug, so the "-2" was added.

In the case of "/cpt-name/test-2/" the post_parent was 0, same as "/test/", so its slug got a "-2."

  • Cc mbox@… added
  • Keywords needs-unit-tests added

I would love to fix this. To do so, we will need some unit tests.

  • Cc mike.schroder@… added
  • Cc thirstcard added

Many of the top Content Management Systems allow the same slug to be used across many different parents. An example of a website that has good information architecture is http://www.riverisland.com.

Considering WordPress has moved away from being a simple blogging tool and into the realm of a powerful CMS, shouldn't we remove the need for sibling slugs to be unique?

  • Milestone changed from Awaiting Review to Future Release

Yes, we should, but it's easier said than done. WP would have to look at the permalink structure to check if the final URL would be ambiguous or not.

comment:11 follow-up: ↓ 12   caekcraft6 months ago

More tests:
I have IA as such at the moment:

/test1/subtest1/  (works perfectly)
/test2/subtest1/  (works perfectly)
/test2/subtest2/  (works perfectly)

When I try to navigate to
/test1/subtest2/, which does not exist, instead of getting a 404 (which I am expecting), I am instead redirected to
/test2/subtest2/, which, from an IA point of view, detrimental. Also, testing needed if normally I would not have access to /test2/subtest2/, after the redirect, will I get a restricted page, or bypass security and view the contents?

comment:12 in reply to: ↑ 11   SergeyBiryukov6 months ago

Replying to caekcraft:

When I try to navigate to /test1/subtest2/, which does not exist, instead of getting a 404 (which I am expecting), I am instead redirected to /test2/subtest2/

Related: #18734

Note: See TracTickets for help on using tickets.