-
Notifications
You must be signed in to change notification settings - Fork 214
WP CLI
Co-Authors Plus registers a set of WP-CLI subcommands under the wp co-authors-plus namespace. They exist for three kinds of job:
- Backfills and migrations — populating missing data after an installation, import or role-remapping.
- Bulk reassignment — renaming, swapping, merging or retargeting co-authors across many posts in one pass.
- Creation from external sources — WXR files, CSV files or existing WP users.
This page covers every subcommand in the plugin. For the highest-value command — create-author-terms-for-posts — there's a dedicated deep-dive at Backfilling coauthor terms for legacy posts.
Before you run any of these on a production site, take a database backup. Most of these commands write, several of them in bulk, and none of them have a dry-run mode unless noted. Test on a staging mirror first.
Seeds author taxonomy terms from post_author for every post that lacks them. The modern, batch-aware backfill — prefer this over create-terms-for-posts.
wp co-authors-plus create-author-terms-for-posts \
[--post-types=<csv>] [--post-statuses=<csv>] [--unbatched] \
[--records-per-batch=<n>] [--specific-post-ids=<csv>] \
[--above-post-id=<id>] [--below-post-id=<id>]Batches 250 posts at a time; sleeps one second every 500 posts. Skips any post that already has author terms, and marks posts whose post_author no longer exists so subsequent runs don't retry them.
See the dedicated page for every flag, examples, and performance notes.
The older, untargeted backfill. Walks the full posts table from the beginning every run and can't be targeted to specific post types, statuses or ID ranges. Still useful for small sites where the extra options aren't worth it; on everything else, prefer create-author-terms-for-posts.
wp co-authors-plus create-terms-for-postsNo arguments. Processes every post type that supports co-authors, 100 posts at a time.
Removes the _cap_skip_backfill post meta that create-author-terms-for-posts sets when it encounters a post whose post_author doesn't exist. Run this if you've since restored or recreated those user accounts and want the backfill to have another go.
wp co-authors-plus delete-postmeta-that-skip-author-term-backfill [--specific-post-ids=<csv>]With no arguments, clears the meta from every post that has it. Pass --specific-post-ids to target individual posts.
A one-shot compatibility fix from the transition to the cap- term prefix. Adds the prefix to any author terms created before the plugin started namespacing them. Safe to run more than once — already-prefixed terms are left alone.
wp co-authors-plus migrate-author-termsYou only need this on sites that were running extremely old CAP versions (pre-3.0). Modern sites can ignore it.
Refreshes each author term's cached post count and description to match its source WP user or guest-author profile. Run after bulk user edits, or if term counts appear stale in the admin.
wp co-authors-plus update-author-termsHistorical cleanup: strips author taxonomy terms from post revisions, where they were accidentally being stored for a time. Safe on any site; a no-op if your revisions are already clean.
wp co-authors-plus remove-terms-from-revisionsEmits CSV-formatted output of posts that are missing author terms, without modifying anything. Useful for auditing before or after a backfill.
wp co-authors-plus list-posts-without-terms [--post_type=<ptype>]Defaults to post. Pass --post_type=page or similar to target another type.
For a named WP user, reassigns every post they are the post_author on to a co-author. Useful when a user account is leaving the site and you want their bylines to migrate to a guest-author profile.
wp co-authors-plus assign-user-to-coauthor \
--user_login=<wp-user-login> \
--coauthor=<co-author-login>Sleeps two seconds every 100 posts.
Reads a post-meta value on each post and uses it to look up a co-author by login. Purpose-built for imports from systems that stash the intended byline in a meta field like _original_import_author.
wp co-authors-plus assign-coauthors \
[--meta_key=<key>] \
[--post_type=<ptype>] \
[--append_coauthors]Defaults: --meta_key=_original_import_author, --post_type=post. By default the matched co-author replaces the post's existing co-authors; pass --append_coauthors to add alongside them.
Replaces one co-author with another on every post they appear on. Supports dry-run.
wp co-authors-plus swap-coauthors \
--from=<user-login> \
--to=<user-login> \
[--post_type=<ptype>] \
[--dry=<dry>]Pass any truthy value (e.g. --dry=1) to run without making changes. Batches 100 posts.
Renames a single co-author. Updates the author term, the guest-author post's post_name, and the cap-user_login meta in one pass, so the slug used in URLs stays consistent.
wp co-authors-plus rename-coauthor \
--from=<old-user-login> \
--to=<new-user-login>Use this rather than editing the guest-author post title directly — the latter leaves the slug and term out of sync.
Migrates author terms either one-at-a-time or in bulk via a mapping file. Handy when you're consolidating duplicate co-author profiles or renaming a batch of slugs.
wp co-authors-plus reassign-terms \
[--author-mapping=<file>] \
[--old_term=<slug>] \
[--new_term=<slug>]- With
--author-mapping=<file>, reads a JSON file mapping old slugs → new slugs and processes every entry. - With
--old_termand--new_term, performs a single migration.
Creates a single guest author from the command line. All args are optional and map to the guest-author profile fields.
wp co-authors-plus create-author \
[--display_name=<name>] \
[--user_login=<slug>] \
[--first_name=<name>] [--last_name=<name>] \
[--website=<url>] \
[--user_email=<email>] \
[--description=<bio>]For every existing WordPress user on the site, creates a guest-author profile that maps back to them. Use this immediately after installing CAP on a site with existing user accounts, so every author already has a guest-author profile that content editors can fall back on.
wp co-authors-plus create-guest-authorsProcesses 100 users per batch with a progress bar.
Creates guest-author profiles from a CSV file. Column headers map to guest-author field slugs (display_name, user_login, first_name, last_name, user_email, website, description, etc.).
wp co-authors-plus create-guest-authors-from-csv --file=<path-to-csv>Creates guest-author profiles from a WordPress WXR export file. Extracts every author referenced in the file and creates a matching guest-author profile.
wp co-authors-plus create-guest-authors-from-wxr --file=<path-to-wxr>All these subcommands honour the usual WP-CLI global flags:
-
--url=<site-url>to target a specific site on multisite installs. -
--user=<login>to act as a specific user (a few of the commands care about capability checks). -
--quietto suppress progress output;--debugto see internal query logging.
- Author terms and guest-author posts are per-site on multisite. Run any backfill once per site you want to touch —
wp site list --field=url | xargs -I{} wp --url={} co-authors-plus create-author-terms-for-postsis a common pattern. -
create-guest-authorsoperates against the current site's users only. Network users with no posts on the current site are skipped.
- Every command that touches many posts includes a deliberate sleep between batches. Don't patch that out — it protects the database from being hammered.
- For very large sites, break
create-author-terms-for-postsinto ID ranges using--above-post-idand--below-post-id, and run the ranges in parallel against a replica-aware database. - Redirect output to a file when running under a scheduler:
wp … > backfill.log 2>&1. Progress output at scale can exhaust terminal scrollback faster than you'd expect.
-
"No author found for user login": the co-author in
--from/--coauthordoesn't exist as either a WP user or a guest author on this site. Check the slug withwp post list --post_type=guest-author --format=idsorwp user list. -
Term counts don't match after a bulk operation: run
update-author-termsto refresh. -
Backfill command returns early: check for the
_cap_skip_backfillmeta on the affected posts; seedelete-postmeta-that-skip-author-term-backfillabove.