Add Custom Post Type Content to Your WordPress RSS Feed

Often your WordPress website will have custom post types, in addition to your normal blog posts, for content such as books, staff, real estate listings, events, portfolio. Sometimes you don’t want this content to go out in your regular blog RSS feed which is the default behavior. But often, the custom post types are valuable content that you would like to share with readers who subscribe to your blog RSS feed or to automatically send out to your email list using the RSS feed in your newsletter service. This WordPress tutorial shows how you can add custom post type content to your WordPress RSS feed.

custom post type in WordPress RSS feed

It’s best to add custom post types individually, because there may be some custom post types generated by some plugins that you would not want to go out in your feed.

First, look at your current feed to see what it’s showing. You want to add /feed to the url for your site in your browser. So http://yoursite.com/feed. If you look at your feed url in Firefox, it will show a list of your latest blog titles with a snippet using the Live Bookmarks feature. If you use, Chrome, you will see a text file with code. You can scan this code for <title> tags, to see your blog post titles.

rss feed xml file

To add your custom post type to this feed, open your child theme functions.php file in a text editor. Add this code section at the bottom.

<?php
// Note: Add only code below to your functions.php

// Add custom post types - cpt1 and cpt2 to main RSS feed.
function mycustomfeed_cpt_feed( $query ) {
        if ( $query->is_feed() )
            $query->set( 'post_type', array( 'post', 'cpt1', 'cpt2' ) ); 
        return $query;
}
add_filter( 'pre_get_posts', 'mycustomfeed_cpt_feed' );

You want to substitute the name of your custom post type for cpt1 and cpt2. You can add as many custom post types as you like.

Then check http://yoursite.com/feed to see if the added post types are in your feed.

Suppose you have an events custom post type. You would see a list of the events on a page with url http://yoursite.com/events. If you also have a custom post type ‘books’, you would see a list of the books at url http://yoursite.com/books.

If you wanted every new event and every new book to go out in your RSS, then the code that you would place in your functions.php would look like this:

<?php
// Note: Add only code below to your functions.php

// Add custom post types - events and books to main RSS feed.
function mycustomfeed_cpt_feed( $query ) {
        if ( $query->is_feed() )
            $query->set( 'post_type', array( 'post', 'events', 'books' ) ); 
        return $query;
}
add_filter( 'pre_get_posts', 'mycustomfeed_cpt_feed' );

If you only wanted the events to go in your feed, then you would only list – 'post', 'events' – in the array list.

If you are using a plugin to create your custom post type, like Sugar Event Calendar, for example, you will need to find the custom post type slug – sc_event. If it’s not listed on the WordPress plugin download page or the Readme file for the plugin, you may need to ask in the support forum.

What custom post types will you add to your WordPress RSS feed?

You can have a beautiful, hardworking website for your small business.

Tell me about your website project for a personalized solution!


Do you need website tips?

Sign up to get easy-to-use WordPress tutorials, Genesis theme customizations, and other helpful tips for your small business website.

Your email address will be used to send you blog posts. Privacy Policy


Comments

14 responses to “Add Custom Post Type Content to Your WordPress RSS Feed”

  1. Mircea says:

    After I searched and tried a couple of other things to get this done, I found your article and now my RSS feed has content from custom post types. Thank you!

  2. JulieDuran says:

    Thanks, Marcy. That worked well for me. Is it possible to also state a specific category for a content type for a feed? For example, mydomain.com/events/weddings/feed?

  3. whoaloic says:

    Hello,
    I get an issue with a CPT ‘cpt1′.
    When I add this CPT with others CPT’, CPT ‘cpt1’ does not show.
    When I put only CPT ‘cpt1’, this CPT shows in the feed.
    I don’t understand what’s happening.

    Any help would be really appreciated.
    Regards

    • Marcy Diaz says:

      You don’t want to use cpt1 and cpt2. You want to use only the slug for your actual custom post type. If you only have one CPT, then you only need to add it after ‘post’.

      In the tutorial, I have:

      You want to substitute the name of your custom post type for cpt1 and cpt2. You can add as many custom post types as you like.

  4. whoaloic says:

    My problem is that I can’t use both cpt1 and cpt2.

  5. whoaloic says:

    I desactivate then reactivate WPML and it works.

  6. ReZa says:

    Hi
    thank you for your Teaching.

    i use edd in my site, when i want to see edd feed, download category and download tag are not shown in a rss feed.

    at all: in a custom post type, how can i add post type category , post type tag to a feed?

    default WordPress feed for default post type, category and tag show nicely.

    i’m waiting for your answare.

  7. Chuck Smith says:

    I am trying to add a CPT to my site feed but am still, for some reason, unsuccessful. The CPT is ‘sermons’ and I edited your code as such but it does not display at feed:
    http://lwumc.org/feed/

    However, the CPT feed works:
    http://lwumc.org/sermons/feed/

    Any advise would be appreciated.

    • Marcy Diaz says:

      I can’t tell what you are using to add the sermons CPT. It may be that the actual custom post type slug is something other than “sermons”, that “sermons” is a rewrite.
      If you’re using a plugin, you can ask in the support what the CPT slug is, or you can look at the code that adds the CPT.
      This is discussed at the end of the post.

      • Chuck Smith says:

        It was a rewrite issue in the CPT code and I have fixed it. Thanks. Your tutorial worked perfectly.

Leave a Reply

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