Home FAQ

27 questions answered

WP-CLI

Answers pulled from across 4wp.dev — plugins, architectures, development, jobs, and audience guides. Powered by the 4WP FAQ registry.

WP-CLI

WP-CLI Core

Can I install WordPress in a subdirectory with WP-CLI?

Yes. Pass the full URL including the path to wp core install –url=. Download and config steps stay the same; only the site URL changes.

Can I run wp core install without wp config create?

No. WordPress needs database credentials in wp-config.php before installation. Without config, WP-CLI cannot connect to MySQL and the install will fail.

Can I use wp core update –minor on production?

Yes, and it is recommended for automated pipelines. The –minor flag restricts updates to the current major branch (e.g. 6.x → 6.x patch), skipping major version jumps.

Do I always need wp db create?

Only when the database named in wp-config.php does not exist yet. On shared hosting the database is often pre-created — then skip this step. On local dev, create it with WP-CLI.

Do I need Git on the server to run this workflow?

No. Step 4 accepts both git pull and tar -xzf. If the server has Git, pull the branch. If not, upload a tar archive via SFTP and extract it. All other steps are identical.

How do I preview plugin updates before applying them?

Run wp plugin update --all --dry-run. This shows which plugins have updates available and what versions they would move to, without making any changes.

Is wp cache flush enough after a theme switch?

For the WordPress object cache, yes. But it does not clear page-level caches (WP Rocket, W3 Total Cache, Varnish, or CDN edge). After the deployment, also purge those separately — otherwise visitors may see the old theme from cache for hours.

Should I pin a WordPress version when downloading?

For most installs, use the latest stable release without –version. Pin a version only when you intentionally need parity with production or a legacy environment.

Should I update plugins before or after core?

Always update core first. Plugin updates frequently declare a minimum WordPress version requirement. Updating plugins against an outdated core can trigger PHP errors if the plugin expects functions added in the newer core version.

What directory should I run wp core download in?

Use an empty directory for a fresh site. WP-CLI downloads core files into the current working directory. Mixing with existing files can leave stale plugins or themes from an old project.

What does wp cache flush actually clear?

It flushes the WordPress object cache — Redis, Memcached, or the built-in transient store, depending on your server setup. It does not clear browser cache or CDN cache. After major updates, also purge your CDN or page cache plugin separately.

What happens if I skip wp db create on a new local site?

wp core install fails because MySQL cannot connect to a database that does not exist. The error looks like a credentials problem but the fix is creating the database first.

What if wp core update fails midway?

WordPress enters maintenance mode at the start and exits on success. If the update fails, the .maintenance file may remain and lock the site. Delete it with wp maintenance-mode deactivate or remove .maintenance from the root. Then restore from the database export you made in step 2.

What if wp plugin deactivate fails because the plugin files are missing?

If the plugin files are in wp-content-old (not on the active path), WP-CLI may error. Use wp plugin deactivate js_composer --skip-plugins to bypass the missing-file check, or update the active_plugins option directly with wp option get active_plugins and wp option update.

What is the correct order to deploy WordPress with WP-CLI?

Download core (wp core download), create configuration (wp config create), create the database (wp db create), then install (wp core install). Each step depends on the previous one.

When is it safe to delete wp-content-old?

After at least one week of stable production traffic. Bugs in a new deployment often surface days later — broken checkout flows, edge-case 404s, plugin conflicts. Keep the backup directory on the server until you are confident, then remove it and move the database dump off-server.

Why is wp core update-db a separate step?

WordPress core updates sometimes include changes to database table structure. wp core update-db applies these schema migrations. Skipping it can cause undefined behavior — WordPress expects a schema version that does not match what is in the database.

Why move wp-content instead of deleting it?

Moving preserves the entire old site — themes, plugins, uploads — at a known path. If anything in the new version is broken, you can restore in two commands: mv wp-content wp-content-broken && mv wp-content-old wp-content, then import the database backup. Deleting removes that option.

Why must I backup the database before updating WordPress?

Updates modify core files and sometimes the database schema. If the update fails or causes incompatibility with a plugin, restoring from a wp db export dump brings the site back to its pre-update state in seconds.

Why run wp search-replace before activating the new theme?

The active theme reads options and postmeta on activation. If those still contain staging URLs, the theme may write them into new records. Fixing URLs first means the theme starts with clean data.

Why use WP-CLI instead of the web installer?

WP-CLI is scriptable and repeatable — the same commands work on local, staging, and CI pipelines. No browser clicks, no upload limits, and easy to document as code.

WP-CLI Database

Does wp db import drop the existing database before importing?

Yes. WP-CLI runs the .sql file against the current database, which typically begins with DROP TABLE IF EXISTS statements for each table. The result is a clean replacement of the existing data, not a merge. This is why the export step before import is critical — anything not in the backup file will not exist after the import.

How do I know the backup I am importing is from the right environment?

Run grep 'siteurl' backup.sql | head -5 before importing. The siteurl value in the dump shows which site and domain the backup came from. If it shows a localhost or staging URL, you will need to run wp search-replace after the import to fix all domain references.

What credentials does wp db import use?

WP-CLI reads the database host, name, user, and password directly from wp-config.php. You do not need to pass credentials on the command line. This is why wp db import backup.sql works without any additional flags.

What if the import fails halfway through?

The database may be in a partially restored state. First, check the error message — it usually points to a specific table or SQL statement. If the import file is valid, try running it again (WP-CLI’s import is generally idempotent for standard WordPress dumps because each table is dropped before recreating). If the file itself is corrupted, you need an earlier backup.

What is the difference between wp db export and a manual mysqldump?

wp db export is a thin wrapper around mysqldump that reads credentials from wp-config.php automatically. The resulting .sql file is compatible with wp db import and standard MySQL import tools. The main advantage over raw mysqldump is that you do not need to manually pass host, user, password, and database name on the command line.

Why run wp core update-db after importing a backup?

The backup captures the database state at the time it was made. If WordPress core or any plugin was updated after that backup, the current PHP code expects a newer schema. wp core update-db applies any pending ALTER TABLE and schema changes that the code expects but the restored database does not yet have.

Still have questions?

Reach out via contacts or explore the plugin docs if you are building with 4WP FAQ yourself.