简体   繁体   中英

Show only custom post type posts in RSS feed

There are tons of ways of adding custom post types to the RSS feed, but I can't seem to find a way to add CPT UI plugin custom post types to CUSTOM POST TYPE exclusive RSS feed to only query these posts.

Is there way to do this?

Give it a try:

 function cptui_add_post_types_to_rss( $query ) {
        // We do not want unintended consequences.
        if ( ! $query->is_feed() ) {
            return;    
        }
    
        // Replace these slugs with the post types you want to include.
        $cptui_post_types = array( 'my_post_type', 'my_other_post_type' );
    
        $query->set(
            'post_type',
            array_merge(
                array( 'post' ),
                $cptui_post_types
            )
        );
    }
    add_filter( 'pre_get_posts', 'cptui_add_post_types_to_rss' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM