Including Custom Post Type in Default WordPress RSS Feed

To control what post types show up in the default WordPress RSS feed, you can add a function to your themes functions.php file (if one doesn't exist, create it in your theme folder) to control what is returned when the RSS feed is requested.

function myfeed_request($qv) {
	// If a request for the RSS feed is made, but the request
	// isn't specifically for a Custom Post Type feed
	if (isset($qv['feed']) && !isset($qv['post_type'])) {
		// Return a feed with posts of post type 'post'
		$qv['post_type'] = array('post');
	}

	return $qv;
}
add_filter('request', 'myfeed_request');

If we wanted to modify this so that the default feed includes 'post' and a entries from Custom Post Type 'thoughts', we can modify the function as follows:

function myfeed_request($qv) {
	// If a request for the RSS feed is made, but the request
	// isn't specifically for a Custom Post Type feed
	if (isset($qv['feed']) && !isset($qv['post_type'])) {
		// Return a feed with posts of post type 'post' and 'thoughts'
		$qv['post_type'] = array('post', 'thoughts');
	}

	return $qv;
}
add_filter('request', 'myfeed_request');

Write a Comment

Comment

  1. Hi Raam, first of all thank you! your code functions perfect to me! Second, I’m a new developer in wordpress and I don’t understand in which moment the parameter $pv has been completed? please Could you teach me?. Thank you.