Import into more than one category

WordPress Event Management, Calendars & Registration Forums iCal Extension Import into more than one category

This topic contains 3 replies, has 2 voices, and was last updated by  Stephen Harris 6 years, 6 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #30667

    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
    #30678

    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
    #30707

    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
    #30819

    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
Viewing 4 posts - 1 through 4 (of 4 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.