How to Enable RSS for custom post type’s

Shortlink:

RSS for custom Post typesHi, Today I will teach you how to get enable rss for custom post type’s.

You can use this link without any coding

http://www.yoursite.com/feed/?post_type=portfolios

Just change the post_type name to the one that you want to create a separate RSS feed for. Are you looking to take it to the next level and make it for a specific custom post type and custom taxonomy? Well that is not hard at all either:

http://www.yoursite.com/feed/?post_type=portfolios&port_cat=development

If you want to have a feed for only one custom post type, that’s easy: Simply use http://example.com/feed/?post_type=yourposttype.

Queries for multiple post types at once are supported internally, however all request parameters are converted to strings by this line:

https://core.trac.WordPress.org/browser/trunk/wp-includes/classes.php?rev=14031#L277.

Otherwise you could probably use something like

http://example.com/feed/?post_type[]=yourposttype1&post_type[]=yourposttype2.

 

 

You Can do this with coding

You will open your functions.php page in your theme folder then input below codes.

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', 'portfolios', 'books', 'store');
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, portfolios, books, and store.

Source: Core Trac Ticket #12943

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!




%d bloggers like this: