Make WordPress Core

Opened 4 years ago

Last modified 2 years ago

#38599 new enhancement

Allow verbose rewrite rules with custom post types

Reported by: smerriman Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Permalinks Keywords:
Focuses: Cc:


Every time I create a custom post type (say, Book) I invariably want a structure like this:

/books/ - static page where I can write all sorts of overview content with all of the formatting provided by the theme's page template (not a basic post type archive)

/books/book-2/ - custom post type permalinks

This is possible by using a rewrite slug of books.

However, if someone then creates a subpage of books, they'll get a 404 error, full stop.

This has been around a long time, and many workarounds have been provided in trying to get verbose rules triggered, such as: https://gist.github.com/mattberridge/2960966

Rewrite rules underwent some major changes a while ago for improved performance (to get %postname% permastructures working well, then there were pretty attachment URLs, etc), which results in these workarounds no longer working. (Custom post type rules get inserted at a place which isn't easy to reorder and conflicts with other rules).

Instead, I have to keep using unique prefixes which make things look messy and confusing to visitors:

/book/book-1/ (even though there is no /book/ page on my site)

Having a nicer structure seems like a very common use case (especially given the number of search results you'll find about workarounds).

I'd like to suggest allowing custom post types to trigger verbose rules in a way that will work.

Change History (0)

Note: See TracTickets for help on using tickets.