WP-CLI lets developers manage WordPress from their terminal.
Modern Fields adds two commands under wp modern-fields to export and import your field groups, custom post types, taxonomies and custom blocks. They use the same JSON file as the Import & export screen: a file exported from one can be imported with the other.
Export via WP-CLI
The export command writes everything to a JSON file in the current folder, named modern-fields-export-<date>.json.
| Effect | |
|---|---|
--file=<file> | Path of the file to write, instead of the default name. |
--groups=<ids> | Comma-separated IDs of the field groups to export. |
--post-types=<ids> | Comma-separated IDs of the custom post types to export. |
--taxonomies=<ids> | Comma-separated IDs of the taxonomies to export. |
--blocks=<ids> | Comma-separated IDs of the custom blocks to export (Modern Fields Pro). |
--stdout | Print the JSON instead of writing a file, to pipe it into another command. |
Each ID option only filters its own type: the types you leave out are still exported in full. --groups=12,34 exports groups 12 and 34, plus every post type, taxonomy and block.
Find an ID
An ID is the number in the URL of the item’s edit screen: post=12 for a field group, id=56 for a post type, a taxonomy or a block. You can also list them from the terminal:
Import with WP-CLI
The import command reads an export file, then creates or updates each item it holds. Items are matched by a unique identifier stored in the file, not by their title or slug: an item already on the site is updated, and a new one is created.
| Effect | |
|---|---|
<file> | Path of the JSON file to import. Required. |
--dry-run | List the items in the file (type, title, identifier) without writing anything. |
--force | Overwrite the items in conflict. |
Conflicts
When an item on the site was modified after the file was exported, the import skips it and reports a conflict, so that it never overwrites more recent changes silently. Check what changed, then run the import again with --force to overwrite it anyway.
--dry-run only lists what the file contains: it doesn’t check for conflicts.
Automate your deployments
With WP-CLI, you can automate your imports and exports when you set up a local site, or in your CI/CD pipeline. To copy your configuration from one site to another:
To version your field groups with your theme instead, see Sync with theme.