WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Tutorials» How to Add Custom Post Types to Your Main WordPress RSS Feed

How to Add Custom Post Types to Your Main WordPress RSS Feed

Last updated on June 22nd, 2012 by Editorial Staff
55 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
How to Add Custom Post Types to Your Main WordPress RSS Feed

Custom Post Types was one of the most hyped feature of WordPress 3.0. This feature alone expanded the horizon of WordPress usage as a Content Management System (CMS). If you are using Custom Post Types, or thinking of custom post types, then you may have the urge to add it into your main RSS Feed. This option is not built-in by default because your main WordPress RSS feed only includes “Posts” not even pages, so custom post types are a long shot. In this article, we will share how you can add Custom Post Types to your main WordPress RSS feeds.

You would need to open your theme’s functions.php file and add the following code within the PHP markup:

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 query to keep the default content type for blog posts “post” in the main RSS feed, and also adding new custom post types.

But what if you have five custom post types in your new project, and you only want to add three to the main RSS feed? Well that shouldn’t be any problem because we will just modify the code slightly to give you the option to only include the ones that you want.

function myfeed_request($qv) {
	if (isset($qv['feed']) && !isset($qv['post_type']))
		$qv['post_type'] = array('post', 'story', 'books', 'movies');
	return $qv;
}
add_filter('request', 'myfeed_request');

If you see in the code above, we simply added an array to modify the post_types that will be shown in the main RSS feed. We are showing the default posts, story, books, and movies.

Source: Core Trac Ticket #12943

55 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • Revealed: Why Building an Email List is so Important Today (6 Reasons)

    Revealed: Why Building an Email List is so Important Today (6 Reasons)

  • How to Start Your Own Podcast (Step by Step)

    How to Start Your Own Podcast (Step by Step)

  • Google Analytics in WordPress

    How to Install Google Analytics in WordPress for Beginners

  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

41 Comments

Leave a Reply
  1. Aidan says:
    Sep 1, 2019 at 2:40 pm

    Hi,

    This doesn’t appear to work with custom post types that are not using a custom taxonomy. We are using a CPT with the ‘category’ taxonomy. Is this why it isn’t working?

    e.g. mysite.com/feed?post_type=news&category=economy

    Reply
    • WPBeginner Support says:
      Sep 4, 2019 at 9:49 am

      It should still work for those custom post types, you may want to ensure you’re adding the correct name for your custom post type

      Reply
  2. Amar says:
    Jan 15, 2019 at 2:46 am

    It worked for me. Thanks!

    Reply
    • WPBeginner Support says:
      Jan 15, 2019 at 2:29 pm

      Glad our article was helpful :)

      Reply
  3. Arijit Biswas says:
    Mar 12, 2017 at 4:34 am

    Worked for me! Thank you.

    Reply
  4. Renier Delport says:
    Dec 5, 2016 at 9:00 am

    Helpful as always!

    Reply
  5. ReZa says:
    Apr 11, 2016 at 5:19 pm

    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.

    Reply
  6. Samuel says:
    Jan 30, 2016 at 7:44 pm

    Feeds are automatically added in the section dedicated for the custom post type example.com/feed/?post_type=books . You can just add an RSS icon linking to the earlier link.

    Reply
  7. Gary says:
    Jan 10, 2016 at 8:51 pm

    The code wasn’t working for me until I created at least one ‘default post type’ post.

    Reply
  8. Trieu To says:
    Dec 24, 2015 at 8:15 pm

    I want to exclude post from post type in feed. How to?

    Reply
  9. Ruben says:
    Dec 4, 2015 at 9:11 pm

    I wanted to include ALL Custom Post Types so I used this first snippet.
    This included submissions to my Jetpack contact form!
    Unfortunately that took me a while to notice!

    Using the 2nd snippet to define each post type in the array fixed the issue.

    Reply
  10. whoaloic says:
    Apr 9, 2015 at 5:24 am

    Hello,
    I meet an issue with a CPT.
    I add a CPT ‘cpt1’ to my feed amont others CPT, but cpt1 does not show in the feed.
    When I put cpt1 alone in the feed, it works.

    any help would be greatly appreciated.
    Regards.

    Reply
    • whoaloic says:
      May 29, 2015 at 7:13 am

      I desactivate then reactivate WPML and it works.

      Reply
      • JMarqz says:
        Dec 24, 2015 at 11:46 am

        I just want to ask you something, you could see your CPT in your-site.com/feed? I’m using CPT and WPML, but my CPT never shows in your-site.com/feed, just my normal posts.

        I follow this comment:

        And all the CPT I choose are showing in the Feed reader but never in your-site.com/feed. I desactivate and reactivate WPML still not showing in the URL. I appreciate a lot if you could tell me if your CPT are showing in the URL for the Feed (your-site.com/feed).

        Reply
  11. Chuck Whelon says:
    Mar 19, 2015 at 4:48 am

    What if you don;t know the names of the custom post types you want to include in your feed (in example 2) – i.e. I have a webcomic,, & I know the custom post-type for that is “webcomic_post”, but I also want to include posts to my portfolio & woo commerce store products. When I use the first version of the code, these items all show up in the feed, pus some other stuff I want to exclude. The problem is that I don;t know the names of the custom post types being used, and I don’t know how to find them out? I did try ‘product’ and ‘portfolio’ but those didn’t work. I am a bit of a noob at WordPress, so apologies if this is a dumb question — Any help much appreciated!

    Reply
    • Nathan says:
      Feb 19, 2016 at 4:18 pm

      When you’re in WordPress, hover over the “Portfolio” link, for example, in the left navigation. This should point you at a URL where you can see all of your Portfolio items. Go to that page and look in the address bar, you’ll see the name of the post type listed there.

      Reply
  12. Ziacinzia says:
    Nov 25, 2014 at 8:16 am

    Hello, could you please advise where exactly should the code go? Thank you

    Reply
    • Hasan Shahzad says:
      Dec 8, 2014 at 9:45 am

      The code needs to be placed at the end of functions.php theme file.

      Reply
  13. Alex Leonard says:
    Jun 19, 2014 at 6:32 am

    Thanks for this – set me in the right direction for a couple of things :)

    Reply
  14. Kasey says:
    May 29, 2014 at 12:24 am

    Hi, thanks for this! where in the page does this code need to be added? At the top? Bottom? Thanks so much!

    Reply
  15. Moaz says:
    Feb 20, 2014 at 5:25 am

    worked like a charm ! thnx :)

    Reply
  16. Neil Curtis says:
    Feb 6, 2014 at 6:28 am

    Cheers, a quick and easy tip that worked straight away for me. I’ve basically got no ‘posts’ but two custom post types so I had nothing showing in my feed before I edited the functions.php.

    cheers again, Neil

    Reply
  17. Mike says:
    Jan 11, 2014 at 12:19 pm

    THANK YOU!!!

    Reply
  18. Sussie T says:
    Jan 7, 2014 at 9:40 am

    So nice! Thank you! That was just what I needed. And so simple.

    Reply
  19. Pranjal says:
    Apr 21, 2013 at 6:37 am

    Excellent tip, works like charm!

    Want to merge WooCommerce feed to main blog’s feed, thanks again!

    Reply
  20. Colin says:
    Mar 30, 2013 at 8:49 pm

    Boom. This just worked perfectly for me, thankyou thankyou thankyou :)

    Reply
  21. Juergen says:
    Mar 22, 2013 at 9:53 am

    Thanks
    just what I needed

    Reply
  22. Luke Rumley says:
    Jan 31, 2013 at 11:16 pm

    I realize this post is older, but it came in handy today, so thanks! One tip for those that use Jetpack and don’t want to embarrass their visitors, use the second method, not the first! The first method publishes the “feedbacks” CPT to the RSS feed, which are all of the contact form submissions from your site. Oops!

    Reply
  23. Ami says:
    Mar 9, 2012 at 9:52 pm

    +1 here, worked great, thank you!

    Reply
  24. MoiMM says:
    Jun 22, 2011 at 6:55 am

    My last changes in my function.php file :

    <code>

    /*———————————————————————————–*//* Add Post format in RSS/*———————————————————————————–*/ function myfeed_request($qv) { if (isset($qv[‘feed’])) $qv[‘post_type’] = get_post_types(array( ‘public’ => true ) ); return $qv;}add_filter(‘request’, ‘myfeed_request’);

    </code>

    Reply
  25. navjotjsingh says:
    Jun 12, 2011 at 11:14 pm

    You should use get_post_types( array( ‘public’ => true ) ) instead of get_post_types() because you may not want the post types which are set not to be a publicly querable to be included in the feed.

    Reply
    • Luke Rumley says:
      Jan 31, 2013 at 11:18 pm

      Ah, that’s a great catch! See my mistake here: http://wordpress.org/support/topic/plugin-jetpack-by-wordpresscom-feedback-custom-post-type-is-created-after-activating-jetpack?replies=3#post-3799791

      Reply
  26. closemarketing says:
    May 30, 2011 at 4:41 pm

    Nice hack!

    Reply
  27. Zeeshan Hamid says:
    Dec 24, 2010 at 9:05 pm

    Thanks!
    I’ve tried every permutation of this over last few weeks and nothing works. I use feedburner, could that be the problem?

    Reply
    • Yotsugi says:
      Jan 22, 2011 at 1:18 pm

      Check this:
      http://wordpress.org/support/topic/update-not-show-a-feed-after-publish-a-custom-post-type?replies=3

      Reply
  28. Anton says:
    Nov 15, 2010 at 2:06 am

    this tutorial shows you a similar way to achieve this and where you dont have to specify each post type – http://www.ballyhooblog.com/add-custom-post-types-wordpress-main-feed/

    Reply
  29. m says:
    Sep 24, 2010 at 10:37 am

    Could you add ‘page’ and so have pages in the feed as well?

    Reply
    • Editorial Staff says:
      Sep 25, 2010 at 8:05 am

      YES. Pages are it’s own custom post type – “page”. So add that along with your other custom post types.

      Reply
      • Adam W. Warner says:
        Dec 30, 2010 at 10:21 am

        I’ve just found this function and implemented this code (the first one for adding all custom post types) and it works great for adding my custom posts type to my main feed.

        However, it has also added my pages to my feed. I thought this should only add posts, not pages?

        How do I exclude pages?

        Reply
      • ahmed sayed says:
        Jun 26, 2015 at 10:48 am

        can you advice more or provided me code for pages

        thank you

        Reply
  30. Chuck says:
    Sep 6, 2010 at 3:14 pm

    running that code in functions caused a white screen of death. Looking into why…

    Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
MonsterInsights
MonsterInsights
Google Analytics made easy for WordPress. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2020 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2020)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2020)
    • SiteGround Reviews from 4196 Users & Our Experts (2020)
    • Bluehost Review from Real Users + Performance Stats (2020)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2020 – Step by Step Guide
Deals & Coupons (view all)
IPVanish Coupon
Get 20% OFF on IPVanish, one of the best VPN service providers for bloggers and WordPress users.
A2 Hosting Coupon Code
A2 Hosting Coupon
Get 66% off A2 Hosting 's premium WordPress hosting.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).
Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress CDN by MaxCDN | WordPress Security by Sucuri.