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

Updated November 15th, 2017
Updated November 15th, 2017
Share this post:
Share on facebook
Share on twitter
Share on reddit
Share on linkedin
Share on pinterest
Share on pocket
Share on email
Share on print

When WordPress 3.0 was launched, innovations such as Custom Post Types caused a sensation among website administrators. Innovations in the platform allowed admins of self-hosted WordPress websites to maximize the use of the platform as a Content Management System (CMS), taking it way beyond the post-by-post nature of blogging.

One of the strengths of WordPress is the ease by which feeds can be generated and tailored to many different uses. Combine this with the ability to create Custom Post Types and you have a variety of useful feeds to choose from and deploy.

It is possible to create RSS feeds tied to Custom Post Types, though they are not automatically generated, unlike for posts and comments.

To discover the feed address for your Custom Post Type, simply key in the URL of your website, plus “/feed/?post_type=(name of post type)”.

For example, if website http://www.cutecats.com/ had a Custom Post Type called “kittens” the feed will look like this: http://www.cutecats.com/feed/?post_type=kittens

Add all Custom Post Types to main feed

In order to add all of your WordPress site’s Custom Post Types to the main RSS feed, you can add this code to the functions.php file of your theme:

function myfeed_request( $qv ) {
if ( isset( $qv['feed'] ) ) {
$qv['post_type'] = get_post_types();
}
return $qv;
}
add_filter( 'request', 'myfeed_request' );

Sometimes, however, you would want to add only a certain Custom Post Type to your WordPress website’s feed. In this case, a different code would have to be used.

Add specific Custom Post Types to main feed

In order to include a specific Custom Post Type to your site’s RSS, you have to add an array to the functions.php file of your theme that changes the post types that will be visible in the main feed.

This code can be used to show Custom Post Types “Dog”, “Catnip”, and “Claws”, for example.

function myfeed_request( $qv ) {
if ( isset( $qv['feed'] ) && !isset( $qv['post_type'] ) ) {
$qv['post_type'] = array( 'dog', 'catnip', 'claws' );
}
return $qv;
}
add_filter( 'request', 'myfeed_request' );

 

Adding separate feeds for each Custom Post Type

If you want, you can also generate separate feeds for each Custom Post Type. This is useful if you want a specific Custom Post Type to remain separate from the main feed.

For example, for Custom Post Type “Catnip”, this can be done by adding the following code to the functions.php file of your theme:

add_action( 'wp_head', 'wprss_my_feeds' );

function my_cpt_feeds() {
$post_types = array('catnip');
foreach( $post_types as $post_type ) {
$feed = get_post_type_archive_feed_link( $post_type );
if ( $feed === '' || !is_string( $feed ) ) {
$feed = get_bloginfo( 'rss2_url' ) . "?post_type=$post_type";
}
printf(__(''),"alternate","application/rss+xml",$feed);
}
}

 

Plugins

There are also useful plugins that you can install in your WordPress site to manage Custom Post Type feeds. If you wish to create a multisite feed, for example, there is Recent Global Posts Feed.

This plugin creates a post feed URL for multiple sites, which can be subscribed to by anyone. It also makes available a Global Post Feed widget.

Share this post:
Share on facebook
Share on twitter
Share on reddit
Share on linkedin
Share on pinterest
Share on pocket
Share on email
Share on print
Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on email

Responses

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

WPLearningLab