Opened 7 years ago
Last modified 6 years ago
#43746 reviewing defect (bug)
Custom post type single post feed returns a 404 if has_archive is set to false when calling register_post_type()
Reported by: | henry.wright | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 4.9.5 |
Component: | Rewrite Rules | Keywords: | 2nd-opinion has-patch needs-testing needs-unit-tests |
Focuses: | Cc: |
Description
When using register_post_type()
, the single post feed returns a 404 if has_archive
is set to false. This seems to happen regardless of the value of feeds
in the rewrite
array. For example:
register_post_type( 'example', array( 'rewrite' => array( 'slug' => 'my-custom-post-type', 'feeds' => true ), 'has_archive' => false ) );
$ curl -IL https://example.com/my-custom-post-type/some-text/feed/ HTTP/1.1 404 Not Found
I'd expect a feed for the post to be built if feeds
is set to true
.
Note I have flushed permalinks.
Attachments (2)
Change History (12)
#2
@
7 years ago
- Keywords has-patch 2nd-opinion added
43746 is an attempt at providing this feature in register_post_type
by introducing a rewrite
key called single_feed
which doesn't care about the has_archive
property.
#3
in reply to:
↑ description
@
7 years ago
- Keywords needs-patch added; has-patch removed
- Milestone changed from Awaiting Review to 5.0
Replying to henry.wright:
I'd expect a feed for the post to be built if
feeds
is set totrue
.
I agree, I don't think we need a new argument here.
The existing feeds
argument could be updated to support single post (comments) feed. If has_archive
is disabled, it would be the only feed generated.
@soulseekah Thanks for the patch! Could you update it to decouple the feeds
argument from has_archive
?
#4
@
6 years ago
Just to add to this discussion, I found this ticket when searching for solutions to why a 404'ing feed is being added to the head on a site I manage.
The comments feed link tag seems to be added to the head so long as comments are open on the post type, which they are. However because I have has_archive set to false, the feed 404's, creating SEO/Crawl issues. After reading the docs on 'register_post_type' I found the 'feeds' param under rewrites and set it to true, expecting it to fix the problem, but it did not, and I eventually found my way here.
#5
@
6 years ago
I just added a new patch that would allow for the expected behavior of feeds => true, decoupling it from has_archive.
A new ticket will probably need to be opened to prevent the comment feed link tag from being added to the head on sites when comment feed permalinks are not being generated because has_archive = false and feeds = false.
Hey, thanks for your report.
This appears to be by design. Types that have no archive will not create feed endpoints as you would expect.
Singe
post
andpage
feeds are comment feeds and are created separately insideWP_Rewrite::rewrite_rules
, specifically inWP_Rewrite::generate_rewrite_rules
.By extension, you are able to create your own custom feed rules on single types by using
WP_Rewrite::generate_rewrite_rules
and hooking into therewrite_rules_array
filter.A quick fix would be to do:
This will generate the needed feed. I am working on a leaner patch.
P.S.: The Rewrite API is insane to work with.