url rewriting - Page and Post return 404 with custom taxonomy

admin2025-06-04  1

I have registered a custom taxonomy on "post" named "cat_modules" with this args:

'rewrite' => array(
        'hierarchical' => true, 
        'slug' => '/',
        'with_front' => false
    )

I used 'hierarchical' => true to have the url structure like 'category/subcateogry' and I used 'slug' => '/' to remove the "cat_modules" from the slug.

These work well on the archive pages but all posts and pages return a 404 error. If I remove 'slug' => '/' from the args everything work well.

P.S In this web site is installed WPML.

I have registered a custom taxonomy on "post" named "cat_modules" with this args:

'rewrite' => array(
        'hierarchical' => true, 
        'slug' => '/',
        'with_front' => false
    )

I used 'hierarchical' => true to have the url structure like 'category/subcateogry' and I used 'slug' => '/' to remove the "cat_modules" from the slug.

These work well on the archive pages but all posts and pages return a 404 error. If I remove 'slug' => '/' from the args everything work well.

P.S In this web site is installed WPML.

Share Improve this question asked Jan 12, 2019 at 13:43 S MadryS Madry 293 bronze badges 2
  • 1 You need something to distinguish it from pages. Otherwise category/subcateogry just looks like a page called subcategory that's a sub-page of category. – Jacob Peattie Commented Jan 12, 2019 at 13:45
  • @JacobPeattie Thank you for your answer! I wasn't thinking about it!! now I understand why also the home page works!! Do you know some tricks or best pratices for do that? I forgot to write that I would like also have this URL structure to post like category\subcategory\post-title. – S Madry Commented Jan 12, 2019 at 14:09
Add a comment  | 

1 Answer 1

Reset to default 0

OK, so you've used / as you taxonomy slug. It means that URL for your term is:

http://example/my-sample-taxonomy-term/

And for pages it will be:

http://example/my-sample-page/

As you can see, there is no way to guess, what type of post should WP search for.

WordPress processes the URLs looping through registered Rewrite Rules and matching given URL against regular expression assigned to current rule.

That means that in your case WP will take first rule that will match correctly and try to display that type of object. And because there are two different objects registering rules that are in conflict, then you'll get 404 errors for some of them.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749018634a315664.html

最新回复(0)