Importing Events via SQL
Importing Events via SQL in the Modern Events Calendar can be done via the following method.
Manually Importing Events via SQL
The first method for importing events to Modern Events Calendar is to use the option in the plugin.
In this method, you can simply go to the MEC dashboard> Import / Export section get the XML output, and then put the action below in the functions.php:
do_action ('mec_import_file', XML_PATH);
For the second method which will be done via SQL, note that MEC events are created using WP post type + a record in [wp_prefix]_mec_events table so you should import both, otherwise, the event is incomplete and it won’t be shown on the front-end of the website.
For importing the post types, you can simply use the solution that you use for other post types such as posts, pages, etc.
For the mec_events records, we suggest creating a SQL export file from your mec_events table on your demo website and then write a simple PHP code to run the .sql file queries into the client website.
You can use codes like this:
$query_file = '/path/to/mec_events.sql';
$queries = file_get_contents($query_file);
$sqls = explode(';', $queries);
// WordPress DB
global $wpdb;
foreach($sqls as $sql)
{
$sql = trim($sql, '; ');
if(trim($sql) == '') continue;
$sql .= ';';
$wpdb->query($sql);
}
Key Considerations While Importing Events to MEC
You should be careful about the WP table prefix.
We suggest changing the prefix in the SQL file to something unique.
For example, change the INSERT INTO wp_mec_events to INSERT INTO #__mec_events in the SQL file and replace #__ with $wpdb-> prefix before calling the query.
Another way is to assign the queries to a PHP variable and then run it by $wpdb->query() function.
Something like this:
global $wpdb;
$query = "INSERT INTO ".$wpdb->prefix."mec_events ......";
$wpdb->query($sql);
Note: The post_id column of the mec_events table should match the Post ID of the event otherwise they won’t link together.
Report Out Dated Content
If you think the content of this page does not reflect updated information, please let us know.
Hello,
The event calendar has a great otion to import locations, organiziers and, most important, events through .csv and column mapping etc… I think that is the most important problem in your plugin. That needs to be done asap because without that……
Hello,
I will forward your comment to our developer team and they’ll surely receive it. If it is possible they will add this feature in the upcoming updates of the Plugin.