• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

WP Thinker

The WordPress Playground

  • Snippets
  • Best
  • Guides
  • Reviews
Home / Wordpress

October 22, 2018 Muhammed Swalih

How to Add Custom Post Types to Main WordPress RSS Feed

How to Add Custom Post Types to Main WordPress RSS Feed

Custom Post Types was a great feature introduced with the WordPress 3.0 update. This feature boosted the popularity of the WordPress content management system to a great extent. Being the world’s best CMS, WordPress took forward a great step of making it to the top peak of success. Now, coming to the Custom post types. By default, the custom post types will not be included in the RSS feed of your website. Thus, the users who subscribed to your newsletters won’t get the notifications of that specific post types.

This is a bad situation when the users will not get notified of your latest updates even if they are subscribed to your blog posts. So, this problem must be solved as soon as possible. We prepared an article on “How to add custom post types to main WordPress RSS feed.” to help you in adding the custom post types to your RSS feed.

To do this, Open the functions.php file of your child theme and add the following code within the PHP markup.

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 feed to keep the current post type (Default posts) alongside the custom post type. But, If you have any post types to exclude, you need to tweak the code a little.

function myfeed_request($qv) {
if (isset($qv['feed']) && !isset($qv['post_type']))
$qv['post_type'] = array('post', 'post_type1', 'post_type2', 'post_type3');
return $qv;
}
add_filter('request', 'myfeed_request');

The above code adds three custom post types to the RSS feed alongside with keeping the default post types. You need to replace the post_type1, post_type2, post_type3 with the post types you want to add to your RSS feed. Be sure to keep the post before the custom post types. If you remove it, the default posts will no longer be added to the RSS feed.

Muhammed Swalih

A WordPress expert who has been tweaking WordPress functions, plugins, themes and almost everything related to WordPress for the past 5+ years.

Primary Sidebar

Related Articles

Footer

WP Thinker is a website that publishes everything related to WordPress, Plugins, Themes, SEO, Blogging, etc.

  • Facebook
  • Twitter
  • Pinterest

Copyright © 2023 · WP Thinker

  • About Us
  • Advertise
  • Write for Us
  • Privacy Policy
  • Terms and Conditions
  • Contact Us
This website uses cookies to serve you better. By continuing to use this website, you agree to our cookie and Privacy Policy.