[wp-trac] [WordPress Trac] #43746: Custom post type single post feed returns a 404 if has_archive is set to false when calling register_post_type()

WordPress Trac noreply at wordpress.org
Fri Apr 13 19:59:29 UTC 2018


#43746: Custom post type single post feed returns a 404 if has_archive is set to
false when calling register_post_type()
---------------------------+------------------------------
 Reporter:  henry.wright   |       Owner:  (none)
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Rewrite Rules  |     Version:  4.9.5
 Severity:  normal         |  Resolution:
 Keywords:                 |     Focuses:
---------------------------+------------------------------
Changes (by soulseekah):

 * component:  Feeds => Rewrite Rules


Comment:

 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` and `page` feeds are comment feeds and are created separately
 inside `WP_Rewrite::rewrite_rules`, specifically in
 `WP_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 the
 `rewrite_rules_array` filter.

 A quick fix would be to do:

 {{{
 add_action( 'rewrite_rules_array', function( $rules ) {
         global $wp_rewrite;
         $wp_rewrite->add_rewrite_tag( '%my-custom-post-type%', 'my-custom-
 post-type/([^/]+)', 'example=' );
         $custom_rules = $wp_rewrite->generate_rewrite_rules( '%my-custom-
 post-type%', EP_NONE, true, true, false, false );
         return $custom_rules + $rules;
 } );
 }}}

 This will generate the needed feed. I am working on a leaner patch.

 P.S.: The Rewrite API is insane to work with.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/43746#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list