How can I make the slug of the taxonomy also the slug of the custom post

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 bl

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/product/product1/ (/product/%postname%/)

The slug I want: aaa/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.

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/product/product1/ (/product/%postname%/)

The slug I want: aaa/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.

Share Improve this question asked Aug 28, 2019 at 7:29 Raul PlanaRaul Plana 191 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 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/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/product/product1/ (/product/%postname%/) to go to aaa/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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745175205a4615153.html

相关推荐

  • How can I make the slug of the taxonomy also the slug of the custom post

    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 bl

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信