Skip to content

Instantly share code, notes, and snippets.

@sidharrell
Created December 3, 2014 20:19
Show Gist options
  • Select an option

  • Save sidharrell/1e7a3390f74d2cbb0065 to your computer and use it in GitHub Desktop.

Select an option

Save sidharrell/1e7a3390f74d2cbb0065 to your computer and use it in GitHub Desktop.
add venue id import to csv import, EE3
// find the first chunk, which should be lines 241-262 of includes/event-management/csv_import.php
// and add the second chunk after. You'll need to add the column to the events.csv file.
//Add category data
$category_names = explode("|", $strings[25]);
foreach ($category_names as $category_name) {
$category_name = trim($category_name);
$category_sql = "SELECT cd.id FROM " . EVENTS_CATEGORY_TABLE . " cd WHERE category_name='%s'";
$cat_id = $wpdb->get_var($wpdb->prepare($category_sql, $category_name));
if ($cat_id == false) {
//fool the admin code into thinking we're adding a category via a POSt
$old_REQUEST_action = $_REQUEST['action'];
$_REQUEST['action'] = 'add';
$_REQUEST['category_name'] = $category_name;
require_once(EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/category-management/add_cat_to_db.php');
add_cat_to_db();
$cat_id = $wpdb->get_var($wpdb->prepare($category_sql, $category_name));
//ok, now that we've fooled it and added teh category, revert the $_REQUEST params
$_REQUEST['action'] = $old_REQUEST_action;
}
$cat_sql_2 = "INSERT INTO " . EVENTS_CATEGORY_REL_TABLE . " (event_id, cat_id) VALUES (%d, %d)";
if ($wpdb->query($wpdb->prepare($cat_sql_2, $last_event_id, $cat_id)) === false) {
print $wpdb->print_error();
}
}
//Add venue data
$venue_ids = explode("|", $strings[26]);
foreach ($venue_ids as $venue_id) {
$venue_id = trim($venue_id);
$venue_sql = "INSERT INTO " . EVENTS_VENUE_REL_TABLE . " (event_id, venue_id) VALUES (%d, %d)";
if ($wpdb->query($wpdb->prepare($venue_sql, $last_event_id, $venue_id)) === false) {
print $wpdb->print_error();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment