Custom function on event import

Home Forums Calendar Products Events Calendar PRO Custom function on event import

  • This topic has 3 replies, 2 voices, and was last updated 8 years, 9 months ago by Mediengruppe Thüringen.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1295654

    We’d like to invoke a custom function when the aggregator imports iCal events.
    This function should do:

    – take an id from the iCal document (it’s our venue id from a third party system, where the locations are previously imported from)
    – select post_id from wp_postmeta where meta_key like ‘_ourThirdPartyVenueIdThatWeImportedEarlierWithAllImporter’ and meta_value = 1234;
    – set this post_id as the _EventVenueID for the event
    – import the event with our custom value

    Is there a filter point to hook in this functionality?

    Or any other/better way to get a relation between location and event, as there’s no location/venue import (for good reason, i see)

    #1297186
    Barry
    Member

    Hi Mediengruppe Thüringen, great question!

    Before a new event is created, the tribe_aggregator_before_insert_event filter runs and provides an opportunity to modify the arguments used in the creation of the new event post.

    Similarly, if it is an existing event which is being updated, the tribe_aggregator_before_update_event filter will run. Callbacks for these hooks can receive not just the event post arguments, but a reference to the aggregator record object which supplies other pieces of information.

    Once the post has actually been created (or updated), the tribe_events_update_meta action will fire: by combining either of the earlier hooks with this one you can target events being created or updated by Event Aggregator and you can then potentially do the work you outlined.

    Here’s a skeleton of how this might look:

    function modify_upserted_ea_event( $event_id ) {
    	// Alter the event according to your needs
    	update_post_meta( $event_id, '_EventVenueID', '123' );
    
    	// Unhook
    	remove_action( 'tribe_events_update_meta', 'modify_upserted_ea_event' );
    }
    
    function listen_for_ea_upserts( $no_change ) {
    	add_action( 'tribe_events_update_meta', 'modify_upserted_ea_event' );
    	return $no_change;
    }
    
    add_filter( 'tribe_aggregator_before_insert_event', 'listen_for_ea_upserts' );
    add_filter( 'tribe_aggregator_before_update_event', 'listen_for_ea_upserts' );

    I hope that gets you started – and good luck with the project!

    #1316329
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Custom function on event import’ is closed to new replies.