Migrating dates from “ec3 event calendar” into the “custom fields”

Oki, I think it is the right time to share some knowledge with you under the Aggressive Copyright indeed ;) .. in the time of SOPA, ACTA, TPP nothing you should worry about :D

We have used the ec3 event calendar for ages. It was a grate plugin that saved our asses when the WP was on the beginning and we too.
As the time goes the plugin has been abandoned and it triggers over too much errors in the no WP version and will in the future indeed.

The time comes and so I heave decided to abandon this plugin in one of our website too.
The plugin it self has many features as ical feed, calendar etc. we do not need. What we need is just two dates representing the beginning of the gig and the end of the gig.
We do not need time! So the code bellow strip the time off and uses the date only, though if you look at the code closely you find the way how to copy the raw date from the ec3 plugin in to the custom fields.

Custom fields?
What is it and how can I make it? These are nice pieces of data you can add to post or page or in taxonomy if you like. By default there is not really user friendly box where you can add them your self, but what I recommend you is to use nice plugin More fields (it triggers some errors when the WP_DEBUG is on, nothing crucial but still) or the new CCTM super complex CMS plugin (You might find it bit overwhelming, it is fairly complex)

// 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
$myrows = $wpdb->get_results("SELECT * FROM wp_ec3_schedule", ARRAY_N);
//var_dump($myrows);

foreach ($myrows as $rows){
// get the dates only
$start_raw = explode( ' ', $rows[2]);
$end_raw = explode( ' ', $rows[3]);
// 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[0] ;
$end = $end_raw[0];
$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,
'event_start', // << 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,
'event_end', // << your custom field name
$end
)
) );
}
write a note if you dare


 

All the content but a few exceptions on this website are under Aggressive Copyright license. By clicking on the button “Yes I do” you agree with the license and you understand all consequences.