$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>url rewriting - Page and Post return 404 with custom taxonomy|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

url rewriting - Page and Post return 404 with custom taxonomy

matteradmin8PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far