Categorize Imported Events

Home Forums Calendar Products Event Aggregator Categorize Imported Events

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #33099

    Hi All,
    I’ve seen the request (https://theeventscalendar.com/support/forums/topic/facebook-events/ and https://theeventscalendar.com/support/forums/topic/facebook-events-feature-requests/) to categorize imported events and so I thought I’d share a code snippet that I’ve written and see if other people can help push it forward.

    The following function and filter sets a category for any imported events. At one point, I tried to also set the Organizer as a tag, but I had a hard time accessing that data for some reason. If you can benefit from this, please use it! If you can improve it, please share your work!

    /**
    * Sets events from Facebook by Tribe Events Facebook to use a predetermined category
    *
    * IMPORTANT: Replace "{CATEGORY ID}" on Line 35 (wp_set_object_terms...) with the ID of the category for imported events on your site.
    * IMPORTANT: This sets a term in the default "category" taxonomy. You may prefer to set the term in the 'tribe_events_cat' taxonomy
    *
    * @param $post_id int id of post being inserted
    * @param $post obj the post object
    *
    * @uses get_post_type()
    * @uses get_post_meta()
    * @uses wp-set_object_terms()
    * @uses wp_is_post_revision()
    *
    * @todo Tag based on event sponsor
    * @todo UI and saved option to select category of imported events
    */
    function mrw_tag_imported_events( $post_id, $post ) {

    // stop if args aren't set or we're not dealing with an event
    if (
    ! ( isset($postId) && isset($post->post_type) )
    && ! get_post_type($post_id) == 'tribe_events'
    ) {
    return;
    }

    // get the field Tribe sets for event source
    $mrw_event_origin = get_post_meta( $post_id, '_EventOrigin', true );

    // if source is facebook and this isn't a revision, set a category for the post
    if( $mrw_event_origin == 'facebook-importer' && !wp_is_post_revision( $post_id ) ) {

    // set category to 'community events'
    wp_set_object_terms( $post_id, {CATEGORY ID}, 'category', true );

    }

    }
    add_action( 'wp_insert_post', 'mrw_tag_imported_events', 11, 2 );

    #33243
    Jonah
    Participant

    Thanks for the contribution! I’ve gone ahead and created a Gist for this too: https://gist.github.com/jonahcoyote/5015669 – we’re in the process of making changes to the plugin so I’ll pass this on to our developer because this might help facilitate this functionality in a future release.

    Cheers,
    – Jonah

Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Categorize Imported Events’ is closed to new replies.