The iCal feed I use to import many of our site’s events does not include past events. When an event has passed, the iCal feed no longer includes this event, and the event is automatically moved to the trash of our WP admin. I can restore an event temporarily, but it gets “re-trashed” when the iCal feed syncs.
I would like our site to include a list of past events, including those imported from this iCal feed. Is there an easy way to “archive” past events imported via iCal without manually recreating an event? Or is there some other way to “disassociate” imported iCal events from the feed imported them?
Ben Coonley
In theory yes, event’s in feed with ID X will have a post meta key _eventorganiser_feed
with value X
. Unfortunately at this point there is no appropriate hook to remove that meta key (and so dissociate the event from the feed) prior to the feed updating.
I’ll add in a eventorganiser_fetch_feed
hook and eventorganiser_fetched_feed
hook (the former of which could be used to remove ‘old’ events prior to the feed being synced in).
In the mean time, the following may work
function my_disassociate_old_events(){
$feeds = eo_get_feeds( array( 'fields' => 'ids' ) );
if( $feeds ){
foreach( $feeds as $feed_id ){
$old_events = eo_get_events( array(
'numberposts' => -1,
'fields' => 'ids',
'no_found_rows' => true,
'showpastevents' => true,
'group_events_by' => 'series',
'update_post_term_cache' => false,
'update_meta_term_cache' => false,
'eo_interval' => 'expired',
'meta_query' => array( array(
'key' => '_eventorganiser_feed',
'value' => $feed_id,
) )
));
if( $old_events ){
foreach( $old_events as $event_id ){
delete_post_meta( $event_id, '_eventorganiser_feed' );
}
}
}
}
}
add_action( 'eventorganiser_ical_feed_sync', 'my_disassociate_old_events', 5 );
Stephen Harris