Remove base slug in permalinks of hierarchical custom post type

隐身守侯 提交于 2020-01-05 06:50:14

问题


I have a hierarchical Custom Post Type called project, registered as follows:

register_post_type( 'project',
    array(
        'public'            => true,
        'hierarchical'      => true,
        'rewrite' => array(
            'with_front' => false
        )
    )
);

The URLs currently look like this:

  • https://example.com/project/hello
  • https://example.com/project/hello/world

I would like the URLs to look like this:

  • https://example.com/hello
  • https://example.com/hello/world

How can I most efficiently accomplish this such that other URLs are not interfered with (e.g. pages, blog posts, other custom post types)?

All the solutions that are currently out there either cause 404s on other pages on the site or do not work correctly with nested URLs.

来源:https://stackoverflow.com/questions/40412917/remove-base-slug-in-permalinks-of-hierarchical-custom-post-type

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