permalinks - Custom post type slug as page slug

admin2025-01-07  5

I have a custom page type dictionary and all of the dictionary items have URLs like this: example/dictionary/item

dictionary has has_archive => false

The problem occurs if I also create a page called Dictionary with an URL example/dictionary

Now, all of the dictionary item pages are giving me an 404 error.

CPT was created using CPT UI


So, my question is: how to make it so that example/dictionary would show a page called "Dictionary" (not an archive) and that all of the items would show on their URLs, example: example/dictionary/item-1 and not show a 404 error instead.

I refreshed permalinks by going settings -> permalinks, and hitting save.

I have a custom page type dictionary and all of the dictionary items have URLs like this: example.com/dictionary/item

dictionary has has_archive => false

The problem occurs if I also create a page called Dictionary with an URL example.com/dictionary

Now, all of the dictionary item pages are giving me an 404 error.

CPT was created using CPT UI


So, my question is: how to make it so that example.com/dictionary would show a page called "Dictionary" (not an archive) and that all of the items would show on their URLs, example: example.com/dictionary/item-1 and not show a 404 error instead.

I refreshed permalinks by going settings -> permalinks, and hitting save.

Share Improve this question edited Apr 17, 2017 at 19:51 Silver Ringvee asked Apr 17, 2017 at 16:08 Silver RingveeSilver Ringvee 1014 bronze badges 3
  • What is your question? – jdm2112 Commented Apr 17, 2017 at 16:10
  • Have you flushed the permalink rules? – Max Yudin Commented Apr 17, 2017 at 16:30
  • updated the question. BTW the page is: reflectivedata.com/analytics-dictionary – Silver Ringvee Commented Apr 17, 2017 at 19:59
Add a comment  | 

2 Answers 2

Reset to default 0

flush your permalinks. Go to settings / permalinks and hit save.

There is one more thing is possible. When you register the custom post type, you can use additional rewrite with_front argument:

$args = array(
    // ( ... your arguments here ... )
    'rewrite' => array(
        'slug' => 'dictionary',
        'with_front' => false // notice here
    ),
    // ( ... more arguments here ... )

This will remove the CPT base (dictionary in your case) from the URL.

And don't forget to flush permalinks each time you change the code relative to them.

See rewrite in the Codex.

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

最新回复(0)