(+84) 463.28.7979

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:

1 function myfeed_request($qv) {
2 if (isset($qv['feed']))
3 $qv['post_type'] = get_post_types();
4 return $qv;
5 }
6 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.

1 function myfeed_request($qv) {
2 if (isset($qv['feed']) && !isset($qv['post_type']))
3 $qv['post_type'] = array('post', 'story', 'books', 'movies');
4 return $qv;
5 }
6 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

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>