You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为WordPress自定义文章类型启用Feed功能?

解决WordPress自定义文章类型Feed无法访问的问题

你需要在自定义文章类型的注册参数中添加Feed路由支持,具体修改如下:

修改点说明

  1. 在rewrite配置数组中加入'feeds' => true,让WordPress生成对应自定义文章类型的Feed重写规则;
  2. 显式设置'query_var' => true(虽public为true时默认启用,显式声明可避免潜在冲突)。

修改后的完整代码

function nd_dosth_register_custom_post_types(){
    //Register Reviews Post Type
    register_post_type( 'dosth_reviews',
        array(
            'labels'  => array(
                'name'           => __( 'Reviews', 'nd_dosth' ),
                'singular_name'  => __( 'Review', 'nd_dosth' ),
                'add_new'        => __( 'Add Review', 'nd_dosth' ),
                'add_new_item'   => __( 'Add New Review', 'nd_dosth' ),
                'edit_item'      => __( 'Edit Review', 'nd_dosth' ),
                'all_items'      => __( 'All Reviews', 'nd_dosth' ),
                'not_found'      => __( 'No Reviews Found', 'nd_dosth' ),
            ),
            'menu_icon'             => 'dashicons-format-quote',
            'public'                => true,
            'exclude_from_search'   => true,
            'has_archive'           => true,
            'hierarchical'          => false,
            'show_in_rest'          => true,
            // 添加feeds到rewrite规则
            'rewrite'               => array( 'slug' => 'reviews', 'feeds' => true ),
            'supports'              => array( 'title', 'editor', 'author', 'custom-fields', 'thumbnail', 'excerpt', 'revisions', 'page-attributes' ),
            //'taxonomies'          => array( 'category', 'post_tag' )
            'menu_position'         => 20,
            // 显式开启query_var
            'query_var'             => true,
        )
    );
}
 
add_action('init', 'nd_dosth_register_custom_post_types');

关键收尾操作:刷新固定链接

修改代码后,进入WordPress后台「设置」→「固定链接」页面,直接点击「保存更改」按钮(无需修改任何选项),这会让WordPress更新站点重写规则,确保Feed路由生效。

完成后,你就可以通过https://website.io/reviews/feed/访问该自定义文章类型的Feed了。

内容的提问来源于stack exchange,提问作者Denis Petrov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 15:17:41