AnswerBun.com

Custom post type Permalinks with hierarchical Taxonomies

WordPress Development Asked by Attila on January 13, 2021

I Would use Custom Post Type and hierarchical Taxonomies with same Slug. Fortunately I found a good solution based on post_type_link filter here from TheDeadMedic.

mysite.com/products/category1/product-name1 
mysite.com/products/category2/product-name2
mysite.com/products/category1/subcategory1/product-name1
mysite.com/products/category2/subcategory2/product-name2
...

The only problem is subcategory pages get 404.

So these URLs work:

mysite.com/products/category1/product-name1
mysite.com/products/category1/subcategory1/product-name1 

But subcategory pages don’t work in hierarchical structure:

mysite.com/products/category1/subcategory1
mysite.com/products/category2/subcategory2

I can only access these subcategories without hierarchical structure. So these URLs work:

mysite.com/products/subcategory1
mysite.com/products/subcategory2

Have you got any idea how I could extend TheDeadMedic’s solution to hierarchical taxonomies too.

One Answer

Add to the taxonomy registration:

'rewrite' => array( 'hierarchical' => true )

Answered by thanhtungit on January 13, 2021

Add your own answers!

Related Questions

No more get_option(‘date_time’) in WordPress 5.5?

1  Asked on February 10, 2021 by wittich

       

How should I tackle this situation?

0  Asked on February 9, 2021 by remus

   

How to create an anonymous forum?

0  Asked on February 8, 2021 by keyrands

   

Detect if REST API is running

2  Asked on February 8, 2021 by tom-j-nowell

 

Create a bulk action to pass user profiles into a CPT

0  Asked on February 6, 2021 by zaesar

     

Can’t update WordPress with Admin Users

0  Asked on February 4, 2021 by charlene-the-web-design-queen

       

Get Child Category only

1  Asked on February 2, 2021 by joamika

   

MULTISITE: Password issue and Error Cant access site

3  Asked on January 31, 2021 by msn_administrator

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir