Add Custom Post Type Content to Your WordPress RSS Feed

Share this on:

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


photo of Marcy Diaz who owns Amethyst Website Design

Comments

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

  1. Mircea Avatar
    Mircea

    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!

    1. Marcy Diaz Avatar

      You’re welcome, Mircea. I’m glad it helped.

  2. JulieDuran Avatar
    JulieDuran

    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?

    1. Marcy Diaz Avatar

      Hi, Julie. I’m glad it worked for you. You can make a separate feed for each custom post category. This is a good tutorial. It will be a separate feed and not your main feed though. All the best!
      http://www.wpbeginner.com/wp-tutorials/how-to-make-a-separate-rss-feed-for-each-custom-post-type-in-wordpress/

  3. whoaloic Avatar
    whoaloic

    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

    1. Marcy Diaz Avatar

      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 Avatar
    whoaloic

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

  5. whoaloic Avatar
    whoaloic

    I desactivate then reactivate WPML and it works.

    1. Marcy Diaz Avatar

      This is good to know! Thank you for sharing it with others!

  6. ReZa Avatar
    ReZa

    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.

    1. Marcy Diaz Avatar

      Thank you for your comment, ReZa! Your question is beyond the scope of this tutorial though. I hope you find an answer.

  7. Chuck Smith Avatar
    Chuck Smith

    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.

    1. Marcy Diaz Avatar

      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.

      1. Chuck Smith Avatar
        Chuck Smith

        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 *

This site uses Akismet to reduce spam. Learn how your comment data is processed.