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
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
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
It worked for me. Thanks!
Glad our article was helpful
Worked for me! Thank you.
Helpful as always!
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.
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.
The code wasn’t working for me until I created at least one ‘default post type’ post.
I want to exclude post from post type in feed. How to?
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.
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.
I desactivate then reactivate WPML and it works.
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).
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!
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.
Hello, could you please advise where exactly should the code go? Thank you
The code needs to be placed at the end of functions.php theme file.
Thanks for this – set me in the right direction for a couple of things
Hi, thanks for this! where in the page does this code need to be added? At the top? Bottom? Thanks so much!
worked like a charm ! thnx
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
THANK YOU!!!
So nice! Thank you! That was just what I needed. And so simple.
Excellent tip, works like charm!
Want to merge WooCommerce feed to main blog’s feed, thanks again!
Boom. This just worked perfectly for me, thankyou thankyou thankyou
Thanks
just what I needed
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!
+1 here, worked great, thank you!
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>
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.
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
Nice hack!
Thanks!
I’ve tried every permutation of this over last few weeks and nothing works. I use feedburner, could that be the problem?
Check this:
http://wordpress.org/support/topic/update-not-show-a-feed-after-publish-a-custom-post-type?replies=3
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/
Could you add ‘page’ and so have pages in the feed as well?
YES. Pages are it’s own custom post type – “page”. So add that along with your other custom post types.
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?
can you advice more or provided me code for pages
thank you
running that code in functions caused a white screen of death. Looking into why…