Skip to content

            Subscribe (RSS | E-Mail)

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');

Posted in PHP, WordPress.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.