{"id":1178,"date":"2019-07-10T15:41:43","date_gmt":"2019-07-10T15:41:43","guid":{"rendered":"https:\/\/webnus.site\/dox\/?p=1178"},"modified":"2023-10-31T10:42:28","modified_gmt":"2023-10-31T10:42:28","slug":"importing-events-via-sql","status":"publish","type":"knowledgebase","link":"https:\/\/webnus.net\/dox\/modern-events-calendar\/importing-events-via-sql\/","title":{"rendered":"Importing Events via SQL"},"content":{"rendered":"\n<p>\u00a0Importing Events via SQL in the <a href=\"http:\/\/webnus.net\" target=\"_blank\" rel=\"noreferrer noopener\">Modern Events Calendar<\/a> can be done via the following method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Manually_Importing_Events_via_SQL\"><\/span>Manually Importing Events via SQL<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The first method for importing events to Modern Events Calendar is to use the option in the plugin.<\/p>\n\n\n\n<p>In this method, you can simply go to the<strong> MEC dashboard&gt; Import \/ Export<\/strong> section get the XML output, and then put the action below in the functions.php:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\ndo_action (&#039;mec_import_file&#039;, XML_PATH);\n<\/pre><\/div>\n\n\n<p>For the second method which will be done via SQL, note that MEC events are created using <strong>WP post type<\/strong> + a record in <strong>[wp_prefix]_mec_events<\/strong> table so you should import both, otherwise, the event is incomplete and it won\u2019t be shown on the front-end of the website.<\/p>\n\n\n\n<p>For importing the post types, you can simply use the solution that you use for other post types such as posts, pages, etc.<\/p>\n\n\n\n<p>For the <strong>mec_events<\/strong> records, we suggest creating a <strong>SQL export file<\/strong> from your <strong>mec_events<\/strong> table on your demo website and then write a simple PHP code to run the <strong>.sql<\/strong> file queries into the client website.<\/p>\n\n\n\n<p>You can use codes like this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\n$query_file = &#039;\/path\/to\/mec_events.sql&#039;;\n$queries = file_get_contents($query_file);\n$sqls = explode(&#039;;&#039;, $queries);\n\/\/ WordPress DB\nglobal $wpdb;\nforeach($sqls as $sql)\n{\n    $sql = trim($sql, &#039;; &#039;);\n    if(trim($sql) == &#039;&#039;) continue;\n\n    $sql .= &#039;;&#039;;\n\n    $wpdb-&gt;query($sql);\n}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Key_Considerations_While_Importing_Events_to_MEC\"><\/span>Key Considerations While Importing Events to MEC<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>You should be careful about the <strong>WP table prefix<\/strong>.<\/p>\n\n\n\n<p>We suggest changing the prefix in the SQL file to something unique.<\/p>\n\n\n\n<p>For example, change the INSERT INTO wp_mec_events to INSERT INTO #__mec_events in the SQL file and replace #__ with $wpdb-&gt; prefix before calling the query.<\/p>\n\n\n\n<p>Another way is to assign the queries to a PHP variable and then run it by $wpdb-&gt;query() function.<\/p>\n\n\n\n<p>Something like this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nglobal $wpdb;\n$query = &quot;INSERT INTO &quot;.$wpdb-&gt;prefix.&quot;mec_events ......&quot;;\n$wpdb-&gt;query($sql);\n<\/pre><\/div>\n\n\n<p><strong>Note:<\/strong> The <strong>post_id<\/strong> column of the <strong>mec_events<\/strong> table should match the Post ID of the event otherwise they won\u2019t link together.<br>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can import your events to MEC in two ways: The first method is to use the option in the plugin. In this method, you can simply go to the MEC dashboard> Import \/ Export<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","knowledgebase_cat":[50],"class_list":["post-1178","knowledgebase","type-knowledgebase","status-publish","hentry","knowledgebase_cat-developer-other"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/webnus.net\/dox\/modern-events-calendar\/wp-json\/wp\/v2\/knowledgebase\/1178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webnus.net\/dox\/modern-events-calendar\/wp-json\/wp\/v2\/knowledgebase"}],"about":[{"href":"https:\/\/webnus.net\/dox\/modern-events-calendar\/wp-json\/wp\/v2\/types\/knowledgebase"}],"author":[{"embeddable":true,"href":"https:\/\/webnus.net\/dox\/modern-events-calendar\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webnus.net\/dox\/modern-events-calendar\/wp-json\/wp\/v2\/comments?post=1178"}],"version-history":[{"count":3,"href":"https:\/\/webnus.net\/dox\/modern-events-calendar\/wp-json\/wp\/v2\/knowledgebase\/1178\/revisions"}],"predecessor-version":[{"id":9799,"href":"https:\/\/webnus.net\/dox\/modern-events-calendar\/wp-json\/wp\/v2\/knowledgebase\/1178\/revisions\/9799"}],"wp:attachment":[{"href":"https:\/\/webnus.net\/dox\/modern-events-calendar\/wp-json\/wp\/v2\/media?parent=1178"}],"wp:term":[{"taxonomy":"knowledgebase_cat","embeddable":true,"href":"https:\/\/webnus.net\/dox\/modern-events-calendar\/wp-json\/wp\/v2\/knowledgebase_cat?post=1178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}