Revise WordPress Filter for Events Calendar RSS Feeds
Budget: $30 – $250 USD
About a month ago, I hired a freelancer to build me a filter that would do two things:
(1) It captures the Start Date and End Date fields from events created in The Events Calendar and adds those fields to the RSS Feeds for the respective Region feeds.
(2) It includes a filter to grab only the next seven days worth of events for that feed, with "days" including either the Start Date or the End Date within that range.
After he completed the project, I discovered that there are a couple of problems with it.
The first problem is that the filter does not sort the items in date order.
The second (and larger) problem is that the feed doesn't use standard title, description, date fields that rss readers expect.
I need to have the event dates and descriptions included in a description field, and I need the event title included in a title field for each item in the feed.
Here is the filter he wrote for me:
/* Filter RSS Feeds, like https://cthap.com/feed/?post_type=tribe_events®ions=hartford-county-happenings */
function add_events_to_rss_feed( $args ) {
if ( isset( $args['feed'] ) && !isset( $args['post_type'] ) ) {
$args['post_type'] = array( 'post' => 'tribe_events',
'meta_query' => array(
array(
'key' => '_EventStartDate',
'value' => date('Y-m-d H:i:s', strtotime('+1 week')),
'compare' => 'date'
)
)
);//array( 'post', 'tribe_events','order'=>'DESC','posts_per_page' => 5 );
//$dummy_query = new WP_Query($args); // the query isn't run if we don't pass any query vars
// $dummy_query->parse_query( $request );
//$dummy_query->set('posts_per_rss', 100);
// Add restriction to only show events within one week
//$dummy_query->set('end_date', date('Y-m-d H:i:s', mktime(23, 59, 59, date('n'), date('j') +6, date('Y'))));
// $args=$dummy_query;
//
//echo "<pre>";print_r($dummy_query);echo "</pre>end";
}
return $args;
}
add_filter( 'request', 'add_events_to_rss_feed' );
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 }
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 );
}
}
/* End Filter RSS Feeds */
This project requires an expertise in WordPress filters as well as experience with RSS feeds from The Events Calendar.
I will ignore any bid that does not describe your plugin development experience as well as your experience with The Events Calendar.
(1) It captures the Start Date and End Date fields from events created in The Events Calendar and adds those fields to the RSS Feeds for the respective Region feeds.
(2) It includes a filter to grab only the next seven days worth of events for that feed, with "days" including either the Start Date or the End Date within that range.
After he completed the project, I discovered that there are a couple of problems with it.
The first problem is that the filter does not sort the items in date order.
The second (and larger) problem is that the feed doesn't use standard title, description, date fields that rss readers expect.
I need to have the event dates and descriptions included in a description field, and I need the event title included in a title field for each item in the feed.
Here is the filter he wrote for me:
/* Filter RSS Feeds, like https://cthap.com/feed/?post_type=tribe_events®ions=hartford-county-happenings */
function add_events_to_rss_feed( $args ) {
if ( isset( $args['feed'] ) && !isset( $args['post_type'] ) ) {
$args['post_type'] = array( 'post' => 'tribe_events',
'meta_query' => array(
array(
'key' => '_EventStartDate',
'value' => date('Y-m-d H:i:s', strtotime('+1 week')),
'compare' => 'date'
)
)
);//array( 'post', 'tribe_events','order'=>'DESC','posts_per_page' => 5 );
//$dummy_query = new WP_Query($args); // the query isn't run if we don't pass any query vars
// $dummy_query->parse_query( $request );
//$dummy_query->set('posts_per_rss', 100);
// Add restriction to only show events within one week
//$dummy_query->set('end_date', date('Y-m-d H:i:s', mktime(23, 59, 59, date('n'), date('j') +6, date('Y'))));
// $args=$dummy_query;
//
//echo "<pre>";print_r($dummy_query);echo "</pre>end";
}
return $args;
}
add_filter( 'request', 'add_events_to_rss_feed' );
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 }
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 );
}
}
/* End Filter RSS Feeds */
This project requires an expertise in WordPress filters as well as experience with RSS feeds from The Events Calendar.
I will ignore any bid that does not describe your plugin development experience as well as your experience with The Events Calendar.