One-way to organized your WordPress website is to create Custom Post Types for special data.
A business might create a Custom Post Type for products and a church might create Custom Post Types for scheduled events, announcements and sermon audio.
Doing this not only helps keep the content, well, managed, but it can come in handy in how you display your data, too. WordPress’ Custom Post Types is the edge of WordPress being a true CMS contender.
So why would want to add Custom Post Types to your general blog post RSS feed?
Although it is nice to keep this data nice and separated on the website, you may want your RSS feed to include all your data. As much as a church blog should not turn into a church picnic announcement page, the RSS feed can be used a bit more dynamically. When church members subscribe to the blog, they are also subscribing to the occasional church announcement, event update or sermon podcast update.
As long as you are not overwhelming the feed, this could be the perfect solution for your church or ministry website (or any other purpose for that matter).
Here is how to add WordPress Custom Post Types to your RSS feed…
You can add this code into your themes functions.php file or build it into your own functionality plugin.
add_filter('request', 'smashing_custom_feed');
function smashing_custom_feed( $vars ) {
if ( isset( $vars['feed'] ) ) {
$vars['post_type'] = get_post_types();
}
return $vars;
}
You can also sort your custom post types—yeah, we’re fancy like that:
add_filter('request', 'smashing_custom_feed');
$post_type_list = array( 'post', 'products' );
function smashing_custom_feed( $vars ) {
if ( isset( $vars['feed'] ) AND !isset( $vars['post_type'] ) ) {
$vars['post_type'] = $post_type_list;
}
return $vars;
}
And that’s it!
Have you used this snippet before? Will you be using it? I would love to hear about!
Speak your mind...