Skip Navigation

[Resolved] How to replace custom taxonomy slug with custom post type slug?

This thread is resolved. Here is a description of the problem and solution.

Problem:
Client wants to use the slug from a custom post type for a taxonomy archive.

Solution:
That's not possible, it is a limitation of WordPress, described below: https://toolset.com/forums/topic/how-to-replace-custom-taxonomy-slug-with-custom-post-type-slug/#post-915700

This support ticket is created 5 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 2.30 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 8 replies, has 2 voices.

Last updated by Himanshu Agarwal 5 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#915231

If the URL is: example.com/taxonomy-name/taxonomy-term/

then how to get this: example.com/custom-post-type/taxonomy-term/

where default "taxonomy-name" is replaced with "custom-post-type".

#915237

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Is the taxonomy used with just one custom post type?

If you go to Toolset > Taxonomies and edit the taxonomy in question, then in the options section the first option is the rewrite slug.

By default this is the taxonomy slug, but you can replace this with whatever *text* you want.

So if you have a custom post type "project" that uses this taxonomy then you could set the rewrite option to "project" to get URLs like example.com/project/taxonomy-term/.

It would be problematic if you used the same taxonomy with several different post types and wanted the rewrite slug to be dynamic, that is not supported.

After making any changes to the rewrite options don't forget to re-save your permalinks to see the changes.

#915579

Thank you for reply.

When i am using same slug from custom post type then this warning shown up:

"Warning: The same value is already used in permalink rewrite rules for the custom post type "custom-post-type". Using it again can cause issues with permalinks."

And main post from that post type giving me 404 page error. I mean this page:

example.com/custom-post-type/main-post-name.

#915612

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, yes, you would have to adda a rewrite rule for the custom post type to free-up the slug if you wanted to use that for the taxonomy archive, they can't both use the same URL slug.

When a URL such as example.com/project/status is entered WordPress needs to resolve the URL and determine whether it is displaying a post (e.g. a project post called status) or displaying a taxonomy archive (the status term of the taxonomy).

Project can't serve both, it has to be one or the other, which you can modify using the rewrite rules to determine how the URL is interpreted, but it must be possible to determine what the URL refers to.

You'll need to use similar but not-identical strings for the URLs for the post type and taxonomy archive.

#915677

Thank you Nigel for reply.

Can you please provide me rewrite code for this or any other reference to do this?

#915685

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

custom-taxonomy-slug.png
custom-post-type-slug.png

You can set either in the options directly.

See the two screenshots, one of which is from the options available when editing the post type, the other from the options available when editing the custom taxonomy.

You can enter whatever string you want to use, but you can't use the same for both.

#915696

Thank you Nigel.

What will be solution if i want both same i mean same slug for both?

#915700

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, as I explained above, you cannot use the same because then WordPress cannot tell when someone enters a URL whether they are trying to display a custom post or a taxonomy archive, which is why they need to be different.

They can be only slightly different.

So if you had a "Projects" custom post type you could use /project/post-name for the custom posts and /projects/term for the taxonomy archive.

#915779

Thank you Nigel.

I understand that this is default wordpress functionality and we cant change that.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.