Skip to content

Instantly share code, notes, and snippets.

@jonahcoyote
Created February 22, 2013 18:51
Show Gist options
  • Save jonahcoyote/5015669 to your computer and use it in GitHub Desktop.
Save jonahcoyote/5015669 to your computer and use it in GitHub Desktop.
The Events Calendar - Facebook Import Set Category
/**
* 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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment