Skip to content

Instantly share code, notes, and snippets.

@jo-snips
Created November 23, 2012 17:09
Show Gist options
  • Save jo-snips/4136499 to your computer and use it in GitHub Desktop.
Save jo-snips/4136499 to your computer and use it in GitHub Desktop.
The Events Calendar: Migrate Events From Other Plugin
if(is_page('Migrate')) {
// example how to get only selected row for particular post id
//$myrows = $wpdb->get_results("SELECT * FROM wp_ec3_schedule WHERE post_id = 7693", ARRAY_N);
// get all the data from the ec3 event calendar
global $wpdb;
$myrows = $wpdb->get_results("SELECT * FROM wp_ec3_schedule", ARRAY_N);
//var_dump($myrows);
foreach ($myrows as $rows){
// get the dates only
$start_raw = $rows[3];
$end_raw = $rows[4];
// strip off the time that I do not want to use. The result is only the date: 2012-01-01
// if you like to use the whole thing 2012-01-01 10:00:00 use the ..raw variables
$start = $start_raw;
$end = $end_raw;
$the_post_id = $rows[1];
// print it all out in to the page, as a feedback
echo $start .' - '.$end.', '.$the_post_id.'<br />';
// update start dates
$wpdb->query( $wpdb->prepare(
"
INSERT INTO $wpdb->postmeta
( post_id, meta_key, meta_value )
VALUES ( %d, %s, %s )
",
array(
$the_post_id,
'_EventStartDate', // << your custom field name
$start
)
) );
// update end dates
$wpdb->query( $wpdb->prepare(
"
INSERT INTO $wpdb->postmeta
( post_id, meta_key, meta_value )
VALUES ( %d, %s, %s )
",
array(
$the_post_id,
'_EventEndDate', // << your custom field name
$end
)
) );
}
@jo-snips
Copy link
Author

  1. Modify line 8 to select event posts from whatever table your plugin store events in.
  2. Add this to your theme's page.php template, and create a page on your site titled "Migrate". Then, when you visit that page the migrate script will run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment