April 15, 2014 by Marcy Diaz
// 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:
// 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.
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.
// 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.
// 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' );
https://amethystwebsitedesign.com/add-custom-post-type-content-to-your-wordpress-rss-feed/