title

Add Custom Post Types To The RSS Feed

 

Add Custom Post Types To The RSS Feed

23 Oct 2013, Posted by antoine in

Not being able to do this easily from the admin area is a big issue. Many website owners separate their content into custom posts, and they also want all of their items to show up in the feeds. Never fear — a function is here!

add_filter('request', 'smashing_custom_feed');
function smashing_custom_feed( $vars ) {
if ( isset( $vars['feed'] ) ) {
$vars['post_type'] = get_post_types();
}
return $vars;
}
While this is great, it forces all of your post types into the feed. If you’d like to add just some of your custom post types to the feed, you can list them separately.
add_filter('request', 'smashing_custom_feed');
$post_type_list = array( 'post', 'products' );
function smashing_custom_feed( $vars ) {
if ( isset( $vars['feed'] ) AND !isset( $vars['post_type'] ) ) {
$vars['post_type'] = $post_type_list;
}
return $vars;
}