How to Generate RSS Feeds for Custom Post Types

If you purchase through a link on our site, we may earn a commission. Learn more.

Custom Post Types were one of the important innovations in WordPress 3.0. They really launched WordPress on the main stage when it comes to usage as a Content Management System (CMS). WordPress is very intuitive in the area of RSS, however it still does not generate automatic feeds for custom post types. So how can we add Custom Post Types to our main WordPress RSS feeds?
Table of Contents
WP Engine High Performance Hosting
BionicWP Hosting

Custom Post Types were one of the important innovations in WordPress 3.0. They really launched WordPress on the main stage when it comes to usage as a Content Management System (CMS). WordPress is very intuitive in the area of RSS, and it also can be queried to generate RSS feeds for Custom Post Types, although it does not provide them automatically as it does for Posts and Comments.

How to Find the RSS Feeds for Custom Post Types

As I referred to, WordPress can be queried to generate RSS feeds for Custom Post Types. Here’s an example:


In this case the post type’s name is wprss_feed so you just need to replace that with your custom post type’s name, and also replace the website domain name of course. That’s all there is to it.

Adding Custom Post Types to Site’s Main Feed

So how can we add all Custom Post Types to our main WordPress RSS feeds?

Insert the following code into your theme’s functions.php file:

function myfeed_request( $qv ) {
    if ( isset( $qv['feed'] ) ) {
        $qv['post_type'] = get_post_types();
    }
    return $qv;
}
add_filter( 'request', 'myfeed_request' );

Adding Specific Custom Post Types to Site’s Main Feed

This code adds custom post type to the main RSS feed for your site, which usually consists only of ‘posts’.

What if you want to choose particular custom post types to add to your site’s feed? That can also be done:

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' );

In this code we’ve added an array that modifies the post types that will be shown in the main RSS feed. We are showing the default posts, projects and websites.

Adding Extra Feeds for Custom Post Types

What if you want to add more feeds to your site? Lets say I have a Project custom post type and would like to make available the latest projects my company has launched via  a specific RSS feed that doesn’t include any other content from my site. Here’s how to do it:

This code adds a feed for every post type. If you’d like to only generate an extra feed for a specific custom post type, you’d have to paste this code instead:

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);
    }
}

Generating Multisite Feeds

If you want to create a global feed from your WordPress Multisite installation, there’s a plugin that does it for you.

Conclusion

In this post, we’ve discussed the topic of generating RSS feeds. If you are also interested in ways that you can import RSS feeds from other websites, our WP RSS Aggregator plugin will probably cover all your needs.

Jean Galea

Jean Galea is an investor, entrepreneur, and blogger. He is the founder of WP Mayor, the plugins WP RSS Aggregator and Spotlight, as well as the Mastermind.fm podcast. His personal blog can be found at jeangalea.com.

Discover more from our , archives ↓

Popular articles ↓

3 Responses

Share Your Thoughts

Your email address will not be published. Required fields are marked *

Claim Your Free Website Tip 👇

Leave your name, email and website URL below to receive one actionable improvement tip tailored for your website within the next 24 hours.

"They identified areas for improvement that we had not previously considered." - Elliot

By providing your information, you'll also be subscribing to our weekly newsletter packed with exclusive content and insights. You can unsubscribe at any time with just one click.