1

I have a custom post type and I need to change the slug to match the category. The same as if in the permalink of the blog posts I associated the category with %category%, but in the custom post with its custom taxonomy.

Example:

Current custom post slug: aaa.com/product/product1/ (/product/%postname%/)

The slug I want: aaa.com/category1/product1/ (/%custom_taxonomy%/%postname%/)

If I rewrite that in the custom post (instead of "product" make it "%custom_taxonomy%") it actually works and give the products the url that I want, but then all of them return 404 error.

At this point I don't know if it is possible what I want to do, the easiest way is create a custom post type for each taxonomy I created so I can customize every slug as I want but that's a lot of work I wan't to know is there a way to make the url like that slug with the category only.

Thank you very much.

1 Answer 1

0

Perhaps a simple way would be to create a custom taxonomy template file which would need to be named taxonomy-$taxonomy.php (where $taxonomy is the name of your custom taxonomy/category).....see this page for more info, and if you scroll down there is a chart that shows how WP uses template files, click on it for a larger image):

https://developer.wordpress.org/themes/basics/template-hierarchy/

You could theoretically also create a custom template file that is for each $term in your custom taxonomy, but that isn't necessary if you don't want to segment your product listings by each category term in your custom category.

THEN you could also use a 301 or 302 redirect statement in your .htaccess file to send any URL requests for aaa.com/product/product1/ (/product/%postname%/) to go to aaa.com/category1/product1/ (/%custom_taxonomy%/%postname%/)

OR simpler still, not bother with a redirect as long as you don't include any links/menu links to the wrong URL but be sure you have links/menu links to your preferred URL easily accessible. If you find that site traffic is still somehow ending up at the wrong URL then do a redirect to deal with it.

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.