Importing/Categorizing Multiple Google Calendars Using Modern Events Calendar by Webnus

As of April 2025, Webnus’ Modern Events Calendar core plugin doesn’t support importing importing multiple Google calendars at a time, or categorizing the imported events.  However, you can fork its code to be able to do so; here are directions below.

  1. Duplicate the PHP file at \wp-content\plugins\modern-events-calendar\app\crons\g-import.php, naming it something else, like g-import-multiple.php
  2. Edit your new file.  Around like 42, you should see this: $calendar_id = $ix[‘google_import_calendar_id’] ?? null;
  3. Right after that line, insert the following code, and customize for your own calendars as imported to Google at https://calendar.google.com/.  Also make sure you capture the id of the event category (e.g. 147 below) for each calendar, which can be found at https://yoursite.com/wp-admin/edit-tags.php?taxonomy=mec_category&post_type=mec-events (when you edit a category you’ll see a tag_id in the url field that you need to copy).
            // Calendars and categories
$calendar_data = [
    'b7ksripubb514jmk47rqovensiseslvt@import.calendar.google.com' => '147', // Outdoor Gear Rental
    'j772lo41ee6qb2227kchb2q1ulaa4dpn@import.calendar.google.com' => '155', // Climbing Wall Programs
    '5sf1femfk3fdqdcvr6fuqaojk1n1go8f@import.calendar.google.com' => '156', // Climbing Wall Drop-in Hours
];
        

On line 54 you’ll see this line of code: $service = new Google_Service_Calendar($client);.  Immediately after that, but before the try { statement, add in this single line of code:

            foreach ($calendar_data as $calendar_id => $category) {
        

On what was originally line 403, you’ll see this code: // Set organizer to the post if ($organizer_id) { wp_set_object_terms($post_id, (int) $organizer_id, ‘mec_organizer’); }

 After that, but immediately before // MEC Dates $dates = $db->select… add the following code to support the categorization of your imported events.

            // Now, assign the category to the event (by name or ID)
            $category_id = null;

            // If the category is provided as an ID
            if (is_numeric($category)) {
                $category_id = $category;
            }

            // If we successfully retrieved the category ID, assign it to the event
            if ($category_id) {
                wp_set_object_terms($post_id, (int) $category_id, 'mec_category');
            }
        

Finally replace the very bottom of the file that shows the following:

            // Delete Events
    foreach ($previously_upserted as $mec_event_id) {
        // It's existing event
        if (in_array($mec_event_id, $posts)) {
            continue;
        }

        wp_trash_post($mec_event_id);
        $posts_deleted[] = $mec_event_id;
    }

    $message = count($posts) ? sprintf(esc_html__('%s google events imported/updated.', 'mec'), count($posts)) : '';
    $message .= count($posts_deleted) ? ' ' . sprintf(esc_html__('%s events trashed successfully.', 'mec'), count($posts_deleted)) : '';

    if (!isset($internal_cron_system)) {
        exit($message);
    }
} catch (Exception $e) {
    if (!isset($internal_cron_system)) {
        $error = $e->getMessage();
        exit($error);
    }
}
        

with the following.  This closes the foreach loop, stops the plugin from deleting events (which for my purposes I didn’t need), and updates the outputted message to show how many events were imported per calendar.  

            // Delete Events
        foreach ($previously_upserted as $mec_event_id) {
            // It's existing event
            if (in_array($mec_event_id, $posts)) {
                continue;
            }

            // Permanently delete the post instead of just trashing
            //wp_delete_post($mec_event_id, true); // true = force delete, bypass trash
            $posts_deleted[] = $mec_event_id;
        }

        $message = count($posts) ? sprintf(esc_html__('%s google events imported/updated for category ID: %s.', 'mec'), count($posts), $category_id) . '<br />' : '';
        //$message .= count($posts_deleted) ? sprintf(esc_html__('%s events trashed successfully.', 'mec'), count($posts_deleted)) . '<br />' : '';

        if (!isset($internal_cron_system)) {
            echo $message;  // Output the message directly with <br /> tags intact
        }

    } catch (Exception $e) {
        if (!isset($internal_cron_system)) {
            $error = $e->getMessage();
            exit($error);
        }
    }
}

        

Obviously you’d finally need to set up some scheduled task to hit your new file periodically (for this purpose I used Task Scheduler to hit https://mysite.com/wp-content/plugins/modern-events-calendar/app/crons/g-import-multiple.php once each night).  Once you’ve visited the link, you should now see your events from multiple Google calendars correctly imported and categorized!