wordpress 如何创建自定义文章类型与启用自定义文章提要?

4nkexdtk  于 12个月前  发布在  WordPress
关注(0)|答案(1)|浏览(120)

代码如下:
什么需要添加到代码启用饲料为这个自定义职位?
这个饲料链接不为我工作与此代码的自定义职位:(
https://website.io/feed/?page_type=reviewshttps://website.io/reviews/feed/

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,
            'rewrite'               => array( 'slug' => 'reviews' ),
            'supports'              => array( 'title', 'editor', 'author', 'custom-fields', 'thumbnail', 'excerpt', 'revisions', 'page-attributes' ),
            //'taxonomies'          => array( 'category', 'post_tag' )
            'menu_position'       => 20,
            'has_archive'           => true,
        )
    );
}
 
add_action('init', 'nd_dosth_register_custom_post_types');

字符串

sg2wtvxw

sg2wtvxw1#

尝试添加以下代码:

add_action('pre_get_posts', function ($query) {
    if ( $query->is_feed() ) {
        $query->set('post_type', array('post', 'dosth_reviews'));
    }
});

字符串

相关问题