WP-CLI Commands
FreeSince 7.5Included in the free Events Manager plugin.
Events Manager adds one command to WP-CLI, wp em migrate. It runs the same migrations and imports as the screens in wp-admin, which is useful for large sites, where a browser run would take a long time, and for scripted or repeated imports.
Two sources are built in:
| Source key | What it brings in |
|---|---|
tec | Events, venues, organizers, categories, tags, tickets and attendees from The Events Calendar. See Migrating from The Events Calendar. |
csv | Events, locations or organizers from a CSV file. |
Events Manager Pro and the add-ons released alongside 7.5 register no WP-CLI commands of their own.
The commands that change data must run as an administrator, because Events Manager checks permissions when it saves events. Add --user= with an administrator's login to those commands, as in the examples. Take a database backup before a first run on a live site.
wp em migrate list
Lists the available sources: whether the source plugin's data was found, whether that plugin is active, how many objects have been migrated, and the state of the last run.
wp em migrate list
wp em migrate status
wp em migrate status <source>
Shows what the source holds, any notices about it, the state and step of the last run, and counts of what has been migrated so far. For the csv source it also shows the ID of each import.
wp em migrate status tec
wp em migrate options
wp em migrate options <source>
Lists the options a source accepts for run, with their defaults and choices. Pass any of them to run as --option=value.
wp em migrate options tec
Options of the tec source:
| Option | Default | Meaning |
|---|---|---|
past_events | true | Include past events. |
tickets | true | Migrate tickets, RSVPs and attendees. |
woo_bookings | em | What WooCommerce ticket orders become: em for Events Manager bookings, em-woocommerce for bookings linked to their WooCommerce orders (needs the Events Manager for WooCommerce add-on), or skip to migrate the tickets only. |
content | true | Replace The Events Calendar's shortcodes and blocks in posts and pages with Events Manager equivalents. |
urls | true | Keep The Events Calendar's web addresses for events, venues, organizers, categories and tags. |
redirects | true | Redirect other old addresses, such as single dates of recurring events and calendar views, once The Events Calendar is deactivated. |
Options of the csv source:
| Option | Default | Meaning |
|---|---|---|
type | events | What the file holds: events, locations or organizers. |
status | publish | The status of imported items: publish, draft or pending. |
date_order | auto | How to read dates written as numbers: auto to work it out from the file, mdy for month first, dmy for day first. |
unsupported_recurrence | dates | What to do with a repeat rule Events Manager can't express: dates imports it as a list of dates, skip leaves the row out. |
skip_duplicates | true | Skip rows already on the site: events with the same name and start, locations with the same name. |
images | true | Download featured images given as web addresses. |
wp em migrate run
wp em migrate run <source> [--resume] [--<option>=<value>] [--file=<path>] [--map=<pairs>] [--delimiter=<character>]
Runs a migration or import to the end. It is safe to run again: objects already migrated are skipped unless they changed at the source since the last run.
| Option | Meaning |
|---|---|
<source> | tec or csv. |
--resume | Continue a run that was interrupted or stopped with an error, in place of starting over. |
--<option>=<value> | Any option of the source, from the tables above. Options you leave out take their defaults. |
--file=<path> | CSV only. The file to import. |
--map=<pairs> | CSV only. Columns that the automatic matching misses, as "Column=field,Column=field". An empty field ("Notes=") leaves that column out. An unknown field name prints the list of valid fields. |
--delimiter=<character> | CSV only. The column separator, when it isn't detected. Write tab for a tab. |
# Migrate everything from The Events Calendar
wp em migrate run tec --user=admin
# The same, keeping bookings linked to their WooCommerce orders
wp em migrate run tec --woo_bookings=em-woocommerce --user=admin
# Import events from a CSV file
wp em migrate run csv --file=events.csv --user=admin
# Import locations, matching two columns by hand
wp em migrate run csv --file=venues.csv --type=locations --map="Site=name,Postal town=town" --user=admin
When it finishes, the command prints the counts for each step. If it stops with an error, fix the cause and run the same command with --resume.
wp em migrate rollback
wp em migrate rollback <source> [--yes] [--import=<id>]
Removes everything the migration created and restores any content it converted. The source plugin's own data is never touched.
| Option | Meaning |
|---|---|
--yes | Skip the confirmation question. |
--import=<id> | CSV only. The import to roll back, by the ID that wp em migrate status csv shows (a short code such as i3f9a2c1b7). Without it, the latest import is rolled back. |
wp em migrate rollback tec --user=admin
wp em migrate rollback csv --import=i3f9a2c1b7 --yes --user=admin
A rollback deletes the migrated events, locations and bookings from Events Manager, including any changes you made to them after the migration.
Troubleshooting
"Run this as an administrator"
run and rollback stop with this message when no user is set or the user can't manage options. Add --user= with an administrator's login or ID.
"Unknown source"
The source key is misspelled. The message lists the keys that exist, and wp em migrate list shows them with their names.
'em' is not a registered wp command
Events Manager is not active on the site WP-CLI is talking to, or is older than 7.5. On multisite, add --url= with the address of the site that has the plugin active.