Make WordPress Core

Opened 8 years ago

Last modified 3 years ago

#37376 new feature request

Make it possible for custom post type to have an archive but no single

Reported by: jason_the_adams's profile jason_the_adams Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.6
Component: Posts, Post Types Keywords: needs-unit-tests has-patch
Focuses: Cc:


Very commonly we'll have testimonials, faqs, and such custom post types, which warrant an archive, but don't make sense to have a single. It's possible to have a post type with no archive and a single, but not the other way around. Funnily enough, I find that we far more often could use what isn't available versus what is.

There are workarounds. One option is to make it a non-publicly-queryable post type and use a page template or something to display the results. Another option I've seen around is to hook into template_redirect on the single and redirect the user. Chances are there's no links on the front-end, so this really only occurs when users click on the link from edit-post admin-side.

Another thing to consider here is SEO plugins and the like which look to the definition of the CPT to build the sitemap. The redirect method ends up putting useless links in the sitemap. The page template method works fine, but obviously means the CPT has to be queried separately.

Would there be a downside to adding a sibling has_single option? If it's true by default then it's backwards compatible, and the single rewrites simply reflect the option.

Attachments (1)

37376.diff (4.4 KB) - added by jason_the_adams 6 years ago.

Download all attachments as: .zip

Change History (6)

#1 @swissspidy
8 years ago

  • Component changed from General to Posts, Post Types

#2 @jason_the_adams
6 years ago

  • Keywords has-unit-tests added

@swissspidy Added a first pass patch to better clarify what I'm thinking. Also added string support for has_single, similar to has_archive, to make it possible to explicitly set the root url for singles. With that it would be possible to have a unique post_name, archive url, and single url.

Please take a look at this and let me know if this is in the right direction. If it is, I'll start to put together tests.

#3 @jason_the_adams
6 years ago

  • Keywords needs-unit-tests added; has-unit-tests removed

#4 @jason_the_adams
6 years ago

  • Keywords has-patch added

This ticket was mentioned in Slack in #core by peterwilsoncc. View the logs.

3 years ago

Note: See TracTickets for help on using tickets.