Hi there,
Is there a way to import a feed into more than one category? I am importing a lot of events and going in and adding additional categories manually to each one takes a lot of time (and also seems to disappear on next fetch).
Thanks,
S
Shimrit Elisar
Hi Shimrit,
Unless you set the category to import to, the events will have their categories reset, because these are typically in the iCal feed itself. The only way to import into multiple categories would be to either split the feed into multiple feeds, each importing into a specified category, or modify the iCal feed so that the appropriate categories are specified there.
Obviously, those two options are only possible if you have control over the iCal feed. If you do not, then it’s possible to write your own code to specify what category an event should be imported into, but you would need to write the logic of mapping a given event from a feed to an appropriate calendar. I can help with implementing this option if that is the option you choose to take.
Stephen Harris
Hi,
Thanks for getting back to me. I am setting the feed to import into a specific category on my end, but I have no control over the ical feed itself, unfortunately. If I split it into different feeds with different categories, won’t it create duplicate events?
Thanks,
S
Shimrit Elisar
Hi Shimrit,
Yes, my advice was based on the assumption that you had control over the source feed. The only way you can map an event to a particular category is to add the logic in yourself. There are hooks that allow you to do this. For instance these two actions fire after an imported event is created or updated:
eventorganiser_ical_sync_event_updated
eventorganiser_ical_sync_event_inserted
Passing the event ID and event array (parsed from the calendar) as arguments:
add_action('eventorganiser_ical_sync_event_inserted', 'my_change_cat_func', 10, 2);
add_action('eventorganiser_ical_sync_event_updated', 'my_change_cat_func', 10, 2);
function my_change_cat_func($event_id, $event){
$categories = ['category-slug']; //Set this based on $event_id or $event
wp_set_post_terms($event_id, $categories, 'event-category');
}
You’ll have to add the logic which determines which event should be mapped to which event category.
Stephen Harris