Over a million developers have joined DZone.

Add Post Types To RSS Feed

DZone's Guide to

Add Post Types To RSS Feed

· Java Zone
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

By default WordPress comes with an in-built RSS feed allowing your visitors to subscribe to your RSS feeds to be alerted to your new articles.

This will normally consist of just the normal blog posts, but as WordPress is a CMS you could have other content types that would suit being in your RSS feed. WordPress allows you to create different post types, out of the box it comes with two posts and pages. But with a bit of code you can create a brand new post type for anything you want.

The below code will look into getting other post types into your website RSS feed.

This first code block will allow you to change the RSS feed to include all posts types in your RSS. First we check to see if we are on the RSS feed page, if so then change the post type variable and replace it with get_post_types(), which returns an array of all post types.

Next time you navigate to the RSS feed you will see other posts types added to the feed.

add_filter('request', 'pu_all_post_type_custom_feed');
function pu_all_post_type_custom_feed( $vars ) 
    if ( isset( $vars['feed'] ) ) {
        $vars['post_type'] = get_post_types();
    return $vars;

But if you don't want to display all post types but only have certain post types then you need to change the code and pass in an array of post types which you want to display in the RSS feed. When a post type is created it needs to register with an ID, you will use this in the array to build up the RSS feed.

add_filter('request', 'pu_specific_post_type_custom_feed');
function pu_specific_post_type_custom_feed( $vars ) 
    $post_type_list = array( 'post', 'downloads' );
    if ( isset( $vars['feed'] ) AND !isset( $vars['post_type'] ) ) {
        $vars['post_type'] = $post_type_list;
    return $vars;

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat


Published at DZone with permission of Paul Underwood, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}