How to Add Custom Post Types to Your WordPress RSS Feed
The WordPress RSS feed displays the recent post only by default. In WordPress, if you use custom post types for other content, then you may want to combine them in your main RSS feed. Read the article until the end if you want to know how to add custom post types to your WordPress RSS feed.
What are Custom Post Type and RSS feed in WordPress?
Custom post types
The custom post type is types of content such as posts and pages. By default, WordPress comes with post types like the post, page, attachment, etc. But, a post type can be any content. You can make your custom post types and name them according to your choice.
WordPress RSS feeds
The WordPress RSS feeds shows your recent post content by default. It is a web feed that allows visitors to track their favorite websites without visiting each site manually.
Why Adding Custom Post Types to RSS Feed?
WordPress comes with post types called posts, pages, attachments, etc. However, you can create additional custom post types to add more content.
It is possible to create RSS feeds linked to your Custom Post Types.
Example:
http://www.mysite.com/feed/?post_type=wprss_feed
Here, the domain is mysite, and the post type is wprss_feed. You can change the domain name and post type name in the above example.
If website http://www.cutedogs.com/ had a Custom Post Type called “puppy,” the feed will look like this: http://www.cutedogs.com/feed/?post_type=puppy.
Adding All Custom Post Types to WordPress RSS Feeds
This method allows you to add all available post types to your main WordPress RSS feed.
You have to add the following code to your WordPress website.
For this, copy the code and paste it to the theme’s functions.php file or a site-specific plugin.
function myfeed_request($qv) { if (isset($qv['feed'])) $qv['post_type'] = get_post_types(); return $qv; } add_filter('request', 'myfeed_request');
This code modifies the default WordPress query to fetch RSS feeds by adding all publicly visible post types into the query.
With this, you add the pages and all other custom post types to your main WordPress RSS feeds.
Add Specific Custom Post Types
By this, you can add specific custom post types to your main WordPress RSS feed.
For this, Copy the below code and paste it to your site.
function myfeed_request( $qv ) { if ( isset( $qv['feed'] ) && !isset( $qv['post_type'] ) ) { $qv['post_type'] = array( 'post', 'project', 'website' ); } return $qv; } add_filter( 'request', 'myfeed_request' );Copy
In this code, we display the default posts, projects, and websites. Now, you can visit your WordPress feed to notice code in action.
Add Extra Feeds for Custom Post Types
If you like to generate an extra feed for a specific custom post type, you have to copy and paste the following code.
add_action( 'wp_head', 'wprss_my_feeds' ); function my_cpt_feeds() { $post_types = array('project'); foreach( $post_types as $post_type ) { $feed = get_post_type_archive_feed_link( $post_type ); if ( $feed === '' || !is_string( $feed ) ) { $feed = get_bloginfo( 'rss2_url' ) . "?post_type=$post_type"; } printf(__('<link rel="%1$s" type="%2$s" href="%3$s" />'),"alternate","application/rss+xml",$feed); } }
CBX RSS Feed for Custom Post Types Plugin
If you don’t want to use the coding method, you can try the CBX RSS Feed for Custom Post Types plugin.
WordPress only displays posts in the RSS feed by default, but it does not show pages or other custom post types in the RSS feed.
This plugin works as RSS Feed Manager for custom post types and helps you to show your Custom Post Types in RSS Feed. Moreover, it gave you the custom control to display custom post types in the RSS feed.
Now, Install and Activate the plugin.
Go to plugins >> search new >> CBX RSS Feed for Custom Post Types >> Install >> Activate.
Then, go to settings >> custom post RSS.
Here, you can select the option you want and then save changes.
With this plugin, you have custom control to display custom post types in the RSS feed.