WP - URL rewrite - custom post type/parent conflict

情到浓时终转凉″ 提交于 2019-12-13 06:49:57

问题


I've been having trouble with this for a day now and can't seem to find a solution (it's probably blatantly obvious I just can't find/see it).

I have a custom post type called product where:

'rewrite' => array( 'slug' => 'product' )

So the posts that I create for that post type have the URLs:

  • example.com/product/first-product
  • example.com/product/second-product
  • example.com/product/third-product

etc..

I've also got a page created called Product Info that has the URL:

  • example.com/product

I'd like to create a page that has Product Info as its parent and therefore has the URL example.com/product/newpage

For me this returns a 404 page not found, I'm guessing this is because WordPress rewrites the URL and checks the product post type for newpage and cannot find it.

How do you do this without WordPress giving a 404 Page Not Found?


回答1:


It's a conflict of slugs.

You will get conflicts if you have the same slug for a page and a CPT that uses that too. So for you, your CPT is using 'product', and your page is too. That's conflicting and causing the 404.

Rename your page Product Info page' slug to product-info.

For safety purposes flush your permalink cache by setting them to Default, saving, then saving them as what you had previously.



来源:https://stackoverflow.com/questions/21430791/wp-url-rewrite-custom-post-type-parent-conflict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!