/**
 * Saves the posts from a remote fetch, assumes posts objects are of a particular format
 */
function ikit_post_external_remote_fetch_save($external_source, $external_source_display_name, $external_source_link_url, $items)
{
    // Find all existing external posts for this source, delete any that are no longer in the feed
    $existing_posts = ikit_get_posts_by_meta(IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE, $external_source, IKIT_POST_TYPE_IKIT_POST_EXTERNAL, 999999);
    $existing_post_exists_by_id = array();
    foreach ($existing_posts as $existing_post) {
        $existing_post_exists_by_id[get_post_meta($existing_post->ID, IKIT_CUSTOM_FIELD_IKIT_POST_EXTERNAL_ID, true)] = 0;
    }
    foreach ($items as $item) {
        $title = $item->title;
        $post_date = $item->post_date;
        $link_url = $item->link_url;
        $description = $item->description;
        $author = $item->author;
        $image_url = $item->image_url;
        $post_id = $item->post_id;
        $post = array('post_title' => $title, 'post_type' => IKIT_POST_TYPE_IKIT_POST_EXTERNAL, 'post_content' => $description, 'post_date' => $post_date, 'edit_date' => true);
        $existing_post_exists_by_id[$post_id] = 1;
        $existing_post = ikit_get_post_by_meta(IKIT_CUSTOM_FIELD_IKIT_POST_EXTERNAL_ID, $post_id, IKIT_POST_TYPE_IKIT_POST_EXTERNAL);
        if ($existing_post == null) {
            $post['post_status'] = 'draft';
            $new_post_id = wp_insert_post($post);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_IKIT_POST_EXTERNAL_ID, $post_id, true);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE, $external_source, true);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE_DISPLAY_NAME, $external_source_display_name, true);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_POST_ATTRIBUTION, $author, true);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_IKIT_POST_EXTERNAL_IMAGE, $image_url, true);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE_LINK_URL, $external_source_link_url, true);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_IKIT_POST_EXTERNAL_LINK_URL, $link_url, true);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_IKIT_POST_EXTERNAL_DATE, $post_date, true);
        } else {
            $post['ID'] = $existing_post->ID;
            $updated_post_id = wp_update_post($post);
            ikit_add_or_update_post_meta($updated_post_id, IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE, $external_source, true);
            ikit_add_or_update_post_meta($updated_post_id, IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE_DISPLAY_NAME, $external_source_display_name, true);
            ikit_add_or_update_post_meta($updated_post_id, IKIT_CUSTOM_FIELD_POST_ATTRIBUTION, $author, true);
            ikit_add_or_update_post_meta($updated_post_id, IKIT_CUSTOM_FIELD_IKIT_POST_EXTERNAL_IMAGE, $image_url, true);
            ikit_add_or_update_post_meta($updated_post_id, IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE_LINK_URL, $external_source_link_url, true);
            ikit_add_or_update_post_meta($updated_post_id, IKIT_CUSTOM_FIELD_IKIT_POST_EXTERNAL_LINK_URL, $link_url, true);
            ikit_add_or_update_post_meta($updated_post_id, IKIT_CUSTOM_FIELD_IKIT_POST_EXTERNAL_DATE, $post_date, true);
        }
    }
    // Delete posts no longer in feed
    foreach ($existing_posts as $existing_post) {
        $exists = $existing_post_exists_by_id[get_post_meta($existing_post->ID, IKIT_CUSTOM_FIELD_IKIT_POST_EXTERNAL_ID, true)];
        if ($exists == 0) {
            wp_delete_post($existing_post->ID, true);
        }
    }
}
示例#2
0
function ikit_job_remote_fetch_save($jobs)
{
    global $wpdb;
    $job_table_name = $wpdb->prefix . IKIT_JOB_TABLE_NAME;
    foreach ($jobs as $active_job) {
        $active_job_id = (string) $active_job->id;
        $job_data = array('id' => $active_job_id, 'title' => $active_job->title, 'description' => ikit_strip_cdata_tags($active_job->description), 'company_name' => ikit_strip_cdata_tags($active_job->company_name), 'contact_information' => ikit_strip_cdata_tags($active_job->contact_information), 'expertise_area' => $active_job->expertise_area, 'experience_length' => $active_job->experience_length, 'city' => $active_job->city, 'state' => $active_job->state, 'country' => $active_job->country, 'other_skills' => $active_job->other_skills, 'apply_online_email' => $active_job->apply_online_email, 'date_approved' => $active_job->date_approved, 'expiration_date' => $active_job->expiration_date, 'job_level' => $active_job->job_level, 'application_url' => ikit_strip_cdata_tags($active_job->application_url), 'application_url_text' => ikit_strip_cdata_tags($active_job->application_url_text), 'submission_details' => ikit_strip_cdata_tags($active_job->submission_details), 'job_functions' => ikit_strip_cdata_tags($active_job->job_functions));
        $rows_affected = $wpdb->query("select id from {$job_table_name} where id = {$active_job_id}");
        if ($rows_affected == 0) {
            $rows_affected = $wpdb->insert($job_table_name, $job_data);
        } else {
            $rows_affected = $wpdb->update($job_table_name, $job_data, array('id' => $active_job_id));
        }
        // Each job has an associated WordPress post to aid with custom fields
        $associated_post = array('post_title' => (string) $active_job->title, 'post_type' => IKIT_POST_TYPE_IKIT_JOB, 'post_status' => 'publish', 'post_content' => (string) ikit_strip_cdata_tags($active_job->description), 'post_date' => (string) $active_job->date_approved);
        $existing_associated_post = ikit_get_post_by_meta(IKIT_CUSTOM_FIELD_IKIT_JOB_ID, $active_job_id, IKIT_POST_TYPE_IKIT_JOB);
        if ($existing_associated_post == null) {
            $new_associated_post_id = wp_insert_post($associated_post);
            if ($new_associated_post_id > 0) {
                // Add the job id to link this post with the job
                add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_JOB_ID, $active_job_id, true);
                add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_JOB_CITY, (string) $active_job->city, true);
                add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_JOB_STATE, (string) $active_job->state, true);
                add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_JOB_LEVEL, (string) $active_job->job_level, true);
                add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_JOB_EXPERTISE_AREA, (string) $active_job->expertise_area, true);
            }
        } else {
            $associated_post['ID'] = $existing_associated_post->ID;
            $updated_associated_post_id = wp_update_post($associated_post);
            if ($updated_associated_post_id > 0) {
                ikit_add_or_update_post_meta($updated_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_JOB_CITY, (string) $active_job->city, true);
                ikit_add_or_update_post_meta($updated_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_JOB_STATE, (string) $active_job->state, true);
                ikit_add_or_update_post_meta($updated_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_JOB_LEVEL, (string) $active_job->job_level, true);
                ikit_add_or_update_post_meta($updated_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_JOB_EXPERTISE_AREA, (string) $active_job->expertise_area, true);
            }
        }
    }
}
function ikit_event_eventbrite_remote_fetch_save($events)
{
    global $wpdb;
    $event_eventbrite_table_name = $wpdb->prefix . IKIT_EVENT_EVENTBRITE_TABLE_NAME;
    foreach ($events as $event) {
        $event = $event->event;
        $event_id = (string) $event->id;
        $event_start_date = ikit_date_without_time($event->start_date);
        $event_end_date = ikit_date_without_time($event->end_date);
        $event_start_time = ikit_time_without_date($event->start_date);
        $event_end_time = ikit_time_without_date($event->end_date);
        $event_data = array('id' => $event_id, 'url' => $event->url, 'start_date' => $event_start_date, 'end_date' => $event_end_date, 'description' => $event->description, 'status' => $event->status, 'title' => $event->title, 'venue_name' => $event->venue->name, 'venue_address' => $event->venue->address, 'venue_address2' => $event->venue->address2, 'venue_city' => $event->venue->city, 'venue_region' => $event->venue->region, 'venue_postal_code' => $event->venue->postal_code, 'venue_country' => $event->venue->country, 'venue_country_code' => $event->venue->country_code, 'venue_longitude' => $event->venue->longitude, 'venue_latitude' => $event->venue->latitude, 'logo' => $event->logo, 'service' => IKIT_EVENT_SERVICE_EVENTBRITE, 'start_time' => $event_start_time, 'end_time' => $event_end_time);
        $rows_affected = $wpdb->query("select id from {$event_eventbrite_table_name} where id = {$event_id}");
        if ($rows_affected == 0) {
            $rows_affected = $wpdb->insert($event_eventbrite_table_name, $event_data);
        } else {
            $rows_affected = $wpdb->update($event_eventbrite_table_name, $event_data, array('id' => $event_id));
        }
        $post_status = 'publish';
        if ($event->status != 'Live' && $event->status != 'Completed' && $event->status != 'Started') {
            $post_status = 'draft';
        }
        // Each event has an associated WordPress post to aid with custom fields
        // searching and an auto-generated admin interface for the event
        $yesterday_gmt = date("Y-m-d H:i:s", time() - 60 * 60 * 24);
        $yesterday_local = date("Y-m-d H:i:s", time() - 60 * 60 * 24 + get_option('gmt_offset') * 3600);
        $associated_post = array('post_title' => (string) $event->title, 'post_type' => IKIT_POST_TYPE_IKIT_EVENT, 'post_status' => $post_status, 'post_content' => (string) $event->description, 'post_date_gmt' => $yesterday_gmt, 'post_date' => $yesterday_local, 'edit_date' => true);
        $event_end_date = ikit_date_without_time($event->end_date);
        $event_start_date = ikit_date_without_time($event->start_date);
        $existing_associated_post = ikit_get_post_by_meta(IKIT_CUSTOM_FIELD_IKIT_EVENT_EVENTBRITE_ID, $event_id, IKIT_POST_TYPE_IKIT_EVENT);
        if ($existing_associated_post == null) {
            $new_associated_post_id = wp_insert_post($associated_post);
            if ($new_associated_post_id > 0) {
                // Add the event id to link this post with the event
                add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_EVENTBRITE_ID, $event_id, true);
                add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_SERVICE, IKIT_EVENT_SERVICE_EVENTBRITE, true);
                add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_STATUS, (string) $event->status, true);
                add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_END_DATE, $event_end_date, true);
                add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_START_DATE, $event_start_date, true);
            }
        } else {
            $associated_post['ID'] = $existing_associated_post->ID;
            $updated_associated_post_id = wp_update_post($associated_post);
            if ($updated_associated_post_id > 0) {
                ikit_add_or_update_post_meta($updated_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_SERVICE, IKIT_EVENT_SERVICE_EVENTBRITE, true);
                ikit_add_or_update_post_meta($updated_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_STATUS, (string) $event->status, true);
                ikit_add_or_update_post_meta($updated_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_END_DATE, $event_end_date, true);
                ikit_add_or_update_post_meta($updated_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_START_DATE, $event_start_date, true);
            }
        }
    }
}
/**
 * Save event feed, saves or updates events in the database
 */
function ikit_event_etouches_remote_fetch_save($events)
{
    global $wpdb;
    $event_table_name = $wpdb->prefix . IKIT_EVENT_ETOUCHES_TABLE_NAME;
    foreach ($events as $event) {
        $event_id = (string) $event->eventid;
        // Do not include error conditioned events or those without live status
        if ($event_id <= 0) {
            continue;
        }
        $event_data = array('id' => $event_id, 'timezone_id' => $event->timezoneid, 'name' => $event->name, 'code' => $event->code, 'start_date' => $event->startdate, 'end_date' => $event->enddate, 'status' => $event->status, 'description' => $event->description, 'program_manager' => $event->programmanager, 'default_language' => $event->defaultlanguage, 'creation_date' => $event->createddatetime, 'last_modified_date' => $event->modifieddatetime, 'location_name' => $event->location->name, 'location_address1' => $event->location->address1, 'location_address2' => $event->location->address2, 'location_city' => $event->location->city, 'location_state' => $event->location->state, 'location_country' => $event->location->country, 'location_phone' => $event->location->phone, 'location_email' => $event->location->email, 'url' => $event->url, 'start_time' => $event->starttime, 'end_time' => $event->endtime, 'close_date' => $event->closedate, 'close_time' => $event->closetime, 'homepage_url' => $event->homepage, 'timezone_description' => $event->timezone, 'folder_id' => $event->folderid, 'folder_name' => $event->foldername, 'client_contact' => $event->clientcontact, 'service' => IKIT_EVENT_SERVICE_ETOUCHES);
        // Allow for null postcodes
        if (empty($event->location->postcode) == false) {
            $event_data['location_postcode'] = $event->location->postcode;
        }
        $rows_affected = $wpdb->query("select id from {$event_table_name} where id = {$event_id}");
        if ($rows_affected == 0) {
            $rows_affected = $wpdb->insert($event_table_name, $event_data);
        } else {
            $rows_affected = $wpdb->update($event_table_name, $event_data, array('id' => $event_id));
        }
        $post_status = 'publish';
        if ($event->status != 'Live' && $event->status != 'Sold Out' && $event->status != 'Closed') {
            $post_status = 'draft';
        }
        // Each event has an associated WordPress post to aid with custom fields
        // searching and an auto-generated admin interface for the event
        $yesterday_gmt = date("Y-m-d H:i:s", time() - 60 * 60 * 24);
        $yesterday_local = date("Y-m-d H:i:s", time() - 60 * 60 * 24 + get_option('gmt_offset') * 3600);
        $associated_post = array('post_title' => (string) $event->name, 'post_type' => IKIT_POST_TYPE_IKIT_EVENT, 'post_status' => $post_status, 'post_content' => (string) $event->description, 'post_date_gmt' => $yesterday_gmt, 'post_date' => $yesterday_local, 'edit_date' => true);
        $existing_associated_post = ikit_get_post_by_meta(IKIT_CUSTOM_FIELD_IKIT_EVENT_ID, $event_id, IKIT_POST_TYPE_IKIT_EVENT);
        if ($existing_associated_post == null) {
            $new_associated_post_id = wp_insert_post($associated_post);
            if ($new_associated_post_id > 0) {
                // Add the event id to link this post with the event
                add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_ID, $event_id, true);
                add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_END_DATE, (string) $event->enddate, true);
                add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_START_DATE, (string) $event->startdate, true);
                add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_STATUS, (string) $event->status, true);
                add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_SERVICE, IKIT_EVENT_SERVICE_ETOUCHES, true);
                // If in the no reg national folder, auto set to disabled reg
                if ($event_data['folder_id'] == IKIT_EVENT_FOLDER_ID_NATIONAL_REGISTRATION_TYPE_DISABLED) {
                    add_post_meta($new_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_REGISTRATION_TYPE, IKIT_CUSTOM_FIELD_IKIT_EVENT_REGISTRATION_TYPE_DISABLED, true);
                }
            }
        } else {
            $associated_post['ID'] = $existing_associated_post->ID;
            // If admin explicity sent event to trash, leave it there
            if ($existing_associated_post->post_status == 'trash') {
                $associated_post['post_status'] = 'trash';
            }
            $updated_associated_post_id = wp_update_post($associated_post);
            if ($updated_associated_post_id > 0) {
                ikit_add_or_update_post_meta($updated_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_END_DATE, (string) $event->enddate, true);
                ikit_add_or_update_post_meta($updated_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_START_DATE, (string) $event->startdate, true);
                ikit_add_or_update_post_meta($updated_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_STATUS, (string) $event->status, true);
                ikit_add_or_update_post_meta($updated_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_SERVICE, IKIT_EVENT_SERVICE_ETOUCHES, true);
                // If in the no reg national folder, auto set to disabled reg
                if ($event_data['folder_id'] == IKIT_EVENT_FOLDER_ID_NATIONAL_REGISTRATION_TYPE_DISABLED) {
                    ikit_add_or_update_post_meta($updated_associated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_REGISTRATION_TYPE, IKIT_CUSTOM_FIELD_IKIT_EVENT_REGISTRATION_TYPE_DISABLED, true);
                }
            }
        }
    }
}
/**
 * Saves the posts from a remote fetch, assumes posts objects are of a particular format
 */
function ikit_event_external_remote_fetch_save($external_source, $external_source_display_name, $external_source_link_url, $items)
{
    global $wpdb;
    $event_external_table_name = $wpdb->prefix . IKIT_EVENT_EXTERNAL_TABLE_NAME;
    // Find all existing external events for this chapter, delete any that are no longer in the feed
    $existing_posts = ikit_get_posts_by_meta(IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE, $external_source, IKIT_POST_TYPE_IKIT_EVENT_EXTERNAL, 999999);
    $existing_post_exists_by_id = array();
    foreach ($existing_posts as $existing_post) {
        $existing_post_exists_by_id[get_post_meta($existing_post->ID, IKIT_CUSTOM_FIELD_IKIT_EVENT_EXTERNAL_ID, true)] = 0;
    }
    foreach ($items as $item) {
        $title = $item->title;
        $link_url = $item->link_url;
        $image_url = $item->image_url;
        $description = $item->description;
        $start_date = $item->start_date;
        $end_date = $item->end_date;
        $start_time = $item->start_time;
        $end_time = $item->end_time;
        $image_url = $item->image_url;
        $location = $item->location;
        $post_id = $item->post_id;
        // Create an event entry
        $event_data = array('id' => $post_id, 'url' => $link_url, 'image_url' => $image_url, 'start_date' => $start_date, 'end_date' => $end_date, 'service' => IKIT_EVENT_SERVICE_EXTERNAL, 'start_time' => $start_time, 'end_time' => $end_time, 'location' => $location);
        $existing_post_exists_by_id[$post_id] = 1;
        $rows_affected = $wpdb->query("select id from {$event_external_table_name} where id = '{$post_id}'");
        if ($rows_affected == 0) {
            $rows_affected = $wpdb->insert($event_external_table_name, $event_data);
        } else {
            $rows_affected = $wpdb->update($event_external_table_name, $event_data, array('id' => $post_id));
        }
        // Each event has an associated WordPress post to aid with custom fields
        // searching and an auto-generated admin interface for the event
        $yesterday_gmt = date("Y-m-d H:i:s", time() - 60 * 60 * 24);
        $yesterday_local = date("Y-m-d H:i:s", time() - 60 * 60 * 24 + get_option('gmt_offset') * 3600);
        $post = array('post_title' => $title, 'post_type' => IKIT_POST_TYPE_IKIT_EVENT_EXTERNAL, 'post_content' => $description, 'post_date_gmt' => $yesterday_gmt, 'post_date' => $yesterday_local, 'edit_date' => true);
        $existing_post = ikit_get_post_by_meta(IKIT_CUSTOM_FIELD_IKIT_EVENT_EXTERNAL_ID, $post_id, IKIT_POST_TYPE_IKIT_EVENT_EXTERNAL);
        if ($existing_post == null) {
            $post['post_status'] = 'draft';
            $new_post_id = wp_insert_post($post);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_EXTERNAL_ID, $post_id, true);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_END_DATE, $end_date, true);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_START_DATE, $start_date, true);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_STATUS, 'Live', true);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_SERVICE, IKIT_EVENT_SERVICE_EXTERNAL, true);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE, $external_source, true);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE_DISPLAY_NAME, $external_source_display_name, true);
            add_post_meta($new_post_id, IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE_LINK_URL, $external_source_link_url, true);
        } else {
            $post['ID'] = $existing_post->ID;
            $updated_post_id = wp_update_post($post);
            ikit_add_or_update_post_meta($updated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_END_DATE, $end_date, true);
            ikit_add_or_update_post_meta($updated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_START_DATE, $start_date, true);
            ikit_add_or_update_post_meta($updated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_STATUS, 'Live', true);
            ikit_add_or_update_post_meta($updated_post_id, IKIT_CUSTOM_FIELD_IKIT_EVENT_SERVICE, IKIT_EVENT_SERVICE_EXTERNAL, true);
            ikit_add_or_update_post_meta($updated_post_id, IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE, $external_source, true);
            ikit_add_or_update_post_meta($updated_post_id, IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE_DISPLAY_NAME, $external_source_display_name, true);
            ikit_add_or_update_post_meta($updated_post_id, IKIT_CUSTOM_FIELD_GENERIC_EXTERNAL_SOURCE_LINK_URL, $external_source_link_url, true);
        }
    }
    foreach ($existing_posts as $existing_post) {
        $external_id = get_post_meta($existing_post->ID, IKIT_CUSTOM_FIELD_IKIT_EVENT_EXTERNAL_ID, true);
        $exists = $existing_post_exists_by_id[$external_id];
        if ($exists == 0) {
            wp_delete_post($existing_post->ID, true);
            // Delete associated database entry
            global $wpdb;
            $table_name = $wpdb->prefix . IKIT_EVENT_EXTERNAL_TABLE_NAME;
            $wpdb->query(sprintf("delete from {$table_name} where id = '%s'", $external_id));
        }
    }
}