> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://support.webnus.net/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Importing Events via SQL

Importing Events via SQL in the [Modern Events Calendar](https://webnus.net) 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.