Events are a custom post type. As such, they will not be included in your site’s main RSS feed by default. While The Events Calendar does provide it’s own RSS feed for subscribing to Events posts via RSS, you might bump into a spot where you’d prefer to combine the Posts and Events feeds together. That’s what we’re going to cover in this article, so put your helmets on!

First off, if you didn’t know Events have their own RSS feed, you can find that at: [your-site]/[events-slug]/feed

Adding events to the main RSS feed

The following snippet will do just that. Add it to your theme’s functions.php file and you should notice an immediate impact:

<?php
// Add Events to RSS Feed
function add_events_to_rss_feed( $args ) {
	if ( isset( $args['feed'] ) && !isset( $args['post_type'] ) ) {
		$args['post_type'] = array( 'post', 'tribe_events');
	}
	return $args;
}

add_filter( 'request', 'add_events_to_rss_feed' );

Add the event dates

The feeds do not automatically include the Event post start and end dates or start and end times. That can overcome by tapping in to the WordPress feed hooks. To add the event start and end dates, add the following to your theme’s functions.php file.

💡 RSS feeds do not offer support for event fields (like start and end times), and probably never will. The following event fields are based upon a draft RSS event spec that was last updated in 2002. The draft appears abandoned, and even the purl.org namespace now 404s. Given the age of RSS and that it is widely being replaced by newer formats, it is likely that no official event namespace will ever come to RSS. Thus adding these fields has a fairly limited utility, and they will not be viewable or of much use in many RSS readers.

<?php
// Add Tribe Event Namespace
add_action( 'rss2_ns', 'events_rss2_namespace' );

function events_rss2_namespace() {
	echo 'xmlns:ev="http://purl.org/rss/2.0/modules/event/"'."\n";
}

// Add Event Dates to RSS Feed
add_action( 'rss_item', 'tribe_rss_feed_add_eventdate' );
add_action( 'rss2_item', 'tribe_rss_feed_add_eventdate' );
add_action( 'commentsrss2_item', 'tribe_rss_feed_add_eventdate' );

function tribe_rss_feed_add_eventdate() {
	if ( ! tribe_is_event() ) {
		return;
	}
	?>
	<ev:tribe_event_meta xmlns:ev="Event">
	<?php if ( tribe_get_start_date() !== tribe_get_end_date() ) { ?>

		<ev:startdate><?php echo tribe_get_start_date(); ?></ev:startdate>
		<ev:enddate><?php echo tribe_get_end_date(); ?></ev:enddate>

	<?php } else { ?>

		<ev:startdate><?php echo tribe_get_start_date(); ?></ev:startdate>

	<?php } ?>
	</ev:tribe_event_meta>

<?php }

Order events by publication date

One final adjustment you may wish to make is to ensure that events, just like posts, are ordered by publication date. An extra snippet can be put in place for that very purpose (if that’s what you want to achieve, of course). This basically tells The Events Calendar not to interfere with the order when events are included.

add_action( 'pre_get_posts', 'custom_teardown_tribe_order_filter', 60 );

function custom_teardown_tribe_order_filter() {
	if ( is_feed() ) {
		remove_filter( 'posts_orderby', array( 'Tribe__Events__Query', 'posts_orderby' ), 10, 2 );
	}
}

What we’ve done here is hooked into pre_get_posts(), fetched Events posts and declared that—if the current query is a feed—to order the Events by the date they were published rather than the date they start.

A Couple Notes

While customizing RSS feeds is totally possible, there are a couple of things to keep in mind when working with them:

  • If the changes you make don’t seem to be saved, try flushing your site’s permalinks by clicking the save button under Settings → Permalinks.
  • There is more than one type of RSS feed on your site. Bone up on the differences and how to access them in the WordPress Codex.

Wrapping Up

These are just a few ways to customize your site’s RSS feed. There is no limit to any other information you want to add to your feed. For more information on customizing feeds, check out this this Digging Into WordPress article. Or, if you have other ideas worth sharing, please let us know!