WordPress Feed for Custom Post Types

If you are using the new custom post types with WordPress you may have noticed that the custom posts do not automatically appear in your feed.

To make the custom post types display you need to edit your functions.php file in the root of your theme adding the following code:

function custom_feed_request($qv) {
	if (isset($qv['feed']) && !isset($qv['post_type'])){
		$qv['post_type'] = get_post_types();
 	}
 	return $qv;
}
add_filter('request', 'custom_feed_request');

Now all post types should show in your feeds.

If you do not want to show all post types in a feed then you can specify only the post types you want:

function custom_feed_request($qv) {
	if (isset($qv['feed']) && !isset($qv['post_type'])){
		$qv['post_type'] = array('post', 'page', 'portfolio');
 	}
 	return $qv;
}
add_filter('request', 'custom_feed_request');

This means that you can easily remove the post type page, or others, from your feed.

Showing Only One Post Type in a Feed

With the custom feed request function created the main feed will show all the specified post types:

www.brightfunction.co.uk/feed/

To show only one post type you can filter the feed using the parameter post_type to specify the post type you want to display:

When viewing the feeds you may need to refresh the page a few times or add an additional query string parameter as the feeds are usually cached by default.

This entry was posted in Programming and tagged . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

*
*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

* = Required