How to add custom post types to your main WordPress RSS feed

Here and there is described how to add custom post types to WordPress RSS feed, but none ways works for me with WP 3.5.1, so I was need to create a new one. Difference is with more sophistical check for types to be included in RSS. Here is the code:

function kc_customs2RSS($qv) {
	if(isset($qv['feed'])) {
		if(!isset($qv['post_type'])) {
			$qv['post_type'] = array('mytype', 'post');
		} else {
			if(!in_array('mytype', $qv['post_type'])) $qv['post_type'][] = 'mytype';
			if(!in_array('post', $qv['post_type'])) $qv['post_type'][] = 'post';
	return $qv;
add_filter('request', 'kc_customs2RSS');

As this is pure PHP code, you can put it in your theme's "functions.php", or in a PHP file inside yours "mu-plugin" directory (create it if not exists), or in your plugin as well. Hope I save some time of yours.

Share this

This entry was posted in Blog, Hacks. Bookmark the permalink.

Leave a Reply