Home › Forums › Calendar Products › Event Aggregator › Categorize Imported Events
- This topic has 1 reply, 2 voices, and was last updated 11 years, 1 month ago by Jonah.
-
AuthorPosts
-
February 20, 2013 at 4:43 pm #33099Association for Women In CommunicationsParticipant
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 );
February 22, 2013 at 10:56 am #33243JonahParticipantThanks 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 -
AuthorPosts
- The topic ‘Categorize Imported Events’ is closed to new replies.