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
In wp_unique_term_slug():
In wp_unique_post_slug():
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:
hello-world-2
) and sometimes truncates them (hello-worl
!) to enforce uniquenessI 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.
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.