CtrlField extends WP-CLI with commands for schema management, data migration, and inspection.
All commands require WP-CLI 2.x and CtrlField active. Commands marked Pro need a valid Pro license.
Migrates existing post meta to the current schema version. Run this after adding fields to a group.
wp ctrlfield migrate --post-type=portfolio
wp ctrlfield migrate --post-type=portfolio --dry-run
wp ctrlfield migrate --post-type=portfolio --batch=50| Flag | Default | Description |
|---|---|---|
--post-type |
required | Post type to migrate |
--dry-run |
false | Show what would change without writing |
--batch |
100 | Posts per batch (reduces memory usage) |
Exports the registered schema as a JSON artifact, to move it between environments.
wp ctrlfield export
wp ctrlfield export --file=schema.json| Flag | Default | Description |
|---|---|---|
--file |
stdout | Output file path |
Imports and validates a JSON artifact made by wp ctrlfield export.
wp ctrlfield import --file=schema.jsonExports field values for the posts of a post type as CSV.
wp ctrlfield export-csv --post-type=portfolio > portfolio.csv
wp ctrlfield export-csv --post-type=portfolio --fields=client_name,status
wp ctrlfield export-csv --post-type=portfolio --status=publish > published.csv| Flag | Default | Description |
|---|---|---|
--post-type |
required | Post type to export |
--fields |
all | Comma-separated field keys |
--status |
any | Post status to export |
Output format: CSV with a header row. Complex fields (group, repeater) are JSON-encoded in their column.
Imports field values from a CSV file.
wp ctrlfield import-csv portfolio.csv --post-type=portfolio --dry-run
wp ctrlfield import-csv portfolio.csv --post-type=portfolio --update-existing
wp ctrlfield import-csv portfolio.csv --post-type=portfolio --create-missing| Flag | Default | Description |
|---|---|---|
--post-type |
required | Post type context |
--update-existing |
false | Update posts with a matching post_id |
--create-missing |
false | Create new posts for rows with post_id=0 |
--dry-run |
false | Report stats without writing |
Validates all registered schemas for duplicate keys, invalid conditions, and missing required options.
wp ctrlfield validate
wp ctrlfield validate --post-type=portfolioThe Schema Inspector's Components tab in the terminal: the components ComponentRegistry::discover() found.
wp ctrlfield components list # key, label, category, files, fields, posts using it, problems
wp ctrlfield components list --format=json # table, json, csv, yaml, count
wp ctrlfield components validate # every problem; exits with an error when a component has one
wp ctrlfield components validate --strict # warnings fail too (CI)Problems are a fields file that does not load, a missing template, a condition inside the component pointing at a field that is not there, and the theme's own checks (ctrlfield/component_issues — see Component Registry).
Generates PHP schema code. It prints to stdout, or writes a file with --write (--force overwrites).
wp ctrlfield scaffold post-type portfolio --label="Project,Projects" --fields="client:text,cover:image"
wp ctrlfield scaffold taxonomy project_category --attach-to=portfolio --hierarchical
wp ctrlfield scaffold field-group portfolio_details --post-type=portfolio --fields="client:text:Client" --write=ctrlfield/portfolio.php
wp ctrlfield scaffold options-page theme_settings --fields="tagline:text"
wp ctrlfield scaffold content-table bookings --fields="name:text,date:date" # Pro storage| Subcommand | Main flags |
|---|---|
post-type <slug> |
--label, --supports, --icon, --fields |
taxonomy <slug> |
--attach-to, --label, --hierarchical, --fields |
field-group <key> |
--post-type, --taxonomy, --context, --options-page, --title, --fields |
options-page <slug> |
--title, --capability, --parent, --fields |
content-table <slug> |
--label, --fields, --no-timestamps |
--fields takes key:type[:label] pairs, separated by commas. Every subcommand also accepts --write, --force and --no-register.
Exports a registered field group definition as a portable JSON schema.
wp ctrlfield export-schema portfolio_details
wp ctrlfield export-schema portfolio_details > schema.jsonGenerates a PHP field group registration file from a JSON schema.
wp ctrlfield import-schema schema.json
wp ctrlfield import-schema schema.json --write=ctrlfield/portfolio.php
wp ctrlfield import-schema schema.json --write=ctrlfield/portfolio.php --force| Flag | Description |
|---|---|
--write=<path> |
Write the generated PHP to a file instead of stdout |
--force |
Overwrite the output file if it already exists |
Introspects an existing database and generates a schema file from the stored field structure. Useful when moving an existing site to CtrlField.
wp ctrlfield generate-schema --post-type=portfolio --output=ctrlfield/portfolio.php