Importing events to Modern Event Calendar

Importing events to Modern Event Calendar can be done via these two methods: 

The first method for importing events to modern event calendar is to use the option in the plugin. In this method, you can simply go to the MEC dashboard> Import / Export section and 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, note that MEC events are created by 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 .= ';';


Key considerations while importing events to modern event calendar

Note: 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 ......";

Note: The post_id column of mec_events table should match the Post ID of the event otherwise they won’t link together

Recommended Posts

0 Comment

No Comment.