# Importing Events via SQL

> Bulk import events into MEC with the XML import hook or directly via SQL, including the mec_events table every event needs.

Source: https://webnus.net/dox/modern-events-calendar/importing-events-via-sql/
Last updated: 2026-11-17

Importing Events via SQL in the [Modern Events Calendar](https://webnus.net/) can be done via the following method.

## Manually Importing Events via SQL {#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:

```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:

```php
$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 {#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.

The following schematic example shows how to use the table prefix. Replace the ellipsis with a complete SQL statement for your installation before running it:

```php
global $wpdb;
$query = "INSERT INTO ".$wpdb->prefix."mec_events ......";
$wpdb->query($query);
```

**Note:** The **post\_id** column of the **mec\_events** table should match the Post ID of the event otherwise they won’t link together.
