[Skip to content](#main)

[→](/)

[![Avunu](/brand/avunu-logo.svg)![Avunu](/brand/avunu-logo-light.svg)](/)[Services](/services/)[Consulting](/services/consulting/)[ERP](/services/erp/)[Odoo](/services/erp/odoo/)[ERPNext](/services/erp/erpnext/)[Custom software](/services/custom-software/)[Devices & IoT](/services/devices-iot/)[Websites](/services/websites/)[Infrastructure](/services/infrastructure/)[Partners](/partners/)

[Work](/work/)[Open source](/open-source/)[Knowledge base](/kb/)[About](/about/)

[About Avunu](/about/)[Team](/about/team/)[Insights](/insights/)[Contact](/contact/)

[Client portal](https://erp.avunu.net/projects)[Start a project](/start/)

- [Services](/services/)[Consulting](/services/consulting/)
- [ERP](/services/erp/)
- [Odoo](/services/erp/odoo/)
- [ERPNext](/services/erp/erpnext/)
- [Custom software](/services/custom-software/)
- [Devices & IoT](/services/devices-iot/)
- [Websites](/services/websites/)
- [Infrastructure](/services/infrastructure/)
- [Partners](/partners/)

[Work](/work/)[Open source](/open-source/)[Knowledge base](/kb/)[About](/about/)

- [About Avunu](/about/)
- [Team](/about/team/)
- [Insights](/insights/)
- [Contact](/contact/)

[Client portal](https://erp.avunu.net/projects)[Start a project](/start/)

[Knowledge base](/kb/)[WordPress](/kb/wordpress/)WP-CLI cookbook

Search the knowledge basePress/

ESC

Jump to

[Browse the knowledge base](/kb/)[Frappe](/kb/frappe/)[ERPNext](/kb/erpnext/)[Odoo](/kb/odoo/)[WordPress](/kb/wordpress/)[NixOS](/kb/nixos/)[Email](/kb/email/)[Linux](/kb/linux/)[Databases](/kb/databases/)[Containers](/kb/containers/)[Proxmox](/kb/proxmox/)[Git & Dev Tools](/kb/git-and-dev-tools/)

↵select↑↓navigateescclose

Search the knowledge base

[Skip to the article](#kb-article)[WordPress](/kb/wordpress/)10 articles

- [Overview](/kb/wordpress/)
- [Admin-only custom post types with custom list columns](/kb/wordpress/custom-post-type-admin/)
- [Docket Cache baseline configuration](/kb/wordpress/docket-cache-configuration/)
- [Gravity Forms](/kb/wordpress/gravity-forms/)
- [Populate Gravity Forms image choices from an ACF image field](/kb/wordpress/gravity-forms-image-choices-acf/)
- [Register custom block styles in a classic theme](/kb/wordpress/block-styles-classic-themes/)
- [Run WordPress cron from the system scheduler](/kb/wordpress/wordpress-cron/)
- [Split a child theme's functions.php into included files](/kb/wordpress/child-theme-file-includes/)
- [WordPress database optimization queries](/kb/wordpress/database-optimization-queries/)
- [WordPress debugging snippets](/kb/wordpress/debugging-snippets/)
- [WP-CLI cookbook](/kb/wordpress/wp-cli-cookbook/)
- [wp-config.php reference](/kb/wordpress/wp-config-reference/)

Other sections[Frappe](/kb/frappe/)[ERPNext](/kb/erpnext/)[Odoo](/kb/odoo/)[NixOS](/kb/nixos/)[Email](/kb/email/)[Linux](/kb/linux/)[Databases](/kb/databases/)[Containers](/kb/containers/)[Proxmox](/kb/proxmox/)[Git & Dev Tools](/kb/git-and-dev-tools/)

In WordPress: 10 articles

[Overview](/kb/wordpress/)[Admin-only custom post types with custom list columns](/kb/wordpress/custom-post-type-admin/)[Docket Cache baseline configuration](/kb/wordpress/docket-cache-configuration/)[Gravity Forms](/kb/wordpress/gravity-forms/)[Populate Gravity Forms image choices from an ACF image field](/kb/wordpress/gravity-forms-image-choices-acf/)[Register custom block styles in a classic theme](/kb/wordpress/block-styles-classic-themes/)[Run WordPress cron from the system scheduler](/kb/wordpress/wordpress-cron/)[Split a child theme's functions.php into included files](/kb/wordpress/child-theme-file-includes/)[WordPress database optimization queries](/kb/wordpress/database-optimization-queries/)[WordPress debugging snippets](/kb/wordpress/debugging-snippets/)[WP-CLI cookbook](/kb/wordpress/wp-cli-cookbook/)[wp-config.php reference](/kb/wordpress/wp-config-reference/)

Other sections[Frappe](/kb/frappe/)[ERPNext](/kb/erpnext/)[Odoo](/kb/odoo/)[NixOS](/kb/nixos/)[Email](/kb/email/)[Linux](/kb/linux/)[Databases](/kb/databases/)[Containers](/kb/containers/)[Proxmox](/kb/proxmox/)[Git & Dev Tools](/kb/git-and-dev-tools/)

WordPressWP-CLI cookbook

Tested WP-CLI recipes for URL changes, bulk deletion, WooCommerce bulk edits, emergency admin access, and reinstalling core or plugins.

UpdatedOct 1, 2026

Applies toWordPress 6.xWP-CLI 2.xWooCommerce 9+

Tagswordpresswp-cliwoocommercemaintenance

Reading time7 min

On this page[Before You Run Anything](#before-you-run-anything)[URLs and Search-Replace](#urls-and-search-replace)[Switch a Site From HTTP to HTTPS](#switch-a-site-from-http-to-https)[Move a Site to a New Domain](#move-a-site-to-a-new-domain)[Bulk Deletion](#bulk-deletion)[Delete All Posts of a Post Type](#delete-all-posts-of-a-post-type)[Delete All Terms in a Taxonomy](#delete-all-terms-in-a-taxonomy)[Pause Cache Purging During Bulk Jobs](#pause-cache-purging-during-bulk-jobs)[WooCommerce](#woocommerce)[Set the Price of Every Product in a Category](#set-the-price-of-every-product-in-a-category)[Delete Orders Older Than a Date](#delete-orders-older-than-a-date)[Users](#users)[Create an Emergency Administrator](#create-an-emergency-administrator)[Integrity and Reinstalls](#integrity-and-reinstalls)[Check for Modified Core and Plugin Files](#check-for-modified-core-and-plugin-files)[Reinstall All Plugins](#reinstall-all-plugins)[Reinstall WordPress Core](#reinstall-wordpress-core)[Roll Back to an Earlier Core Version](#roll-back-to-an-earlier-core-version)[Database Checks](#database-checks)[One-Liner WordPress Migration](#one-liner-wordpress-migration)

These are the WP-CLI commands Avunu reaches for most often during migrations, cleanups, and recoveries. Run them from the WordPress root directory (where `wp-config.php` lives), or add `--path=/var/www/example.com/htdocs` to point at it.

## Before You Run Anything

**Run as the web server user**, not root, so new files get the right owner: `sudo -u www-data wp ...`. If you must run as root, WP-CLI requires `--allow-root`. Avoid it where you can.

**Back up first.**`wp db export` writes a SQL dump to the current directory.

**Use `--dry-run`** on commands that support it (`search-replace` does) and read the counts before running for real.

After bulk changes, run `wp cache flush` so the object cache doesn't serve stale data.

## URLs and Search-Replace

`wp search-replace` is safe for serialized PHP data (widgets, options, page builder content), unlike a raw SQL `REPLACE()`.

### Switch a Site From HTTP to HTTPS

Limit the replacement to your own domain. A bare `'http://' 'https://'` also rewrites links to external sites that may not support HTTPS.

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">search-replace</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">'http://example.com'</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">'https://example.com'</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--skip-columns=guid</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--dry-run</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">search-replace</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">'http://example.com'</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">'https://example.com'</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--skip-columns=guid</span>
```

### Move a Site to a New Domain

For example, after copying a staging site to production:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">search-replace</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">'https://staging.example.com'</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">'https://example.com'</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--skip-columns=guid</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--dry-run</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">search-replace</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">'https://staging.example.com'</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">'https://example.com'</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--skip-columns=guid</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">option</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">get</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">home</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">option</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">get</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">siteurl</span>
```

Notes:

`--skip-columns=guid` leaves post GUIDs alone. They're permanent identifiers that feed readers rely on, not links.

Add `--all-tables-with-prefix` to include plugin tables that share the WordPress prefix, or `--network` on multisite.

If `home` and `siteurl` still show the old URL (for example when they're defined in `wp-config.php`), fix them with `wp option update home 'https://example.com'` or `wp config set WP_HOME ...`.

## Bulk Deletion

Warning

These commands delete content permanently. `--force` skips the trash. Take a backup and double-check the post type or taxonomy name first.

### Delete All Posts of a Post Type

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">post</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">list</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--post_type=</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">POST_TYPE</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--post_status=any</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--format=ids</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">|</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">xargs</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-r</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">post</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">delete</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--force</span>
```

`--post_status=any` includes drafts and private posts, which `wp post list` skips by default. `xargs -r` avoids "argument list too long" on large sets and does nothing when the list is empty.

### Delete All Terms in a Taxonomy

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">term</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">list</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">TAXONOM</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">Y</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--field=term_id</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">|</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">xargs</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-r</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">term</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">delete</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">TAXONOM</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">Y</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span>
```

Use the taxonomy's registered name (`category`, `post_tag`, `product_cat`, or a custom one like `my_taxonomy`).

### Pause Cache Purging During Bulk Jobs

Page-cache plugins that purge on every change (LiteSpeed Cache is a common one) can make bulk deletes crawl. Deactivate the plugin for the job, then purge once at the end:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">plugin</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">deactivate</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">litespeed-cache</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">term</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">list</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">TAXONOM</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">Y</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--field=term_id</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">|</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">xargs</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-r</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">term</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">delete</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">TAXONOM</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">Y</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">plugin</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">activate</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">litespeed-cache</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">litespeed-purge</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">all</span>
```

## WooCommerce

Use WooCommerce's CRUD functions (`wc_get_products()`, `wc_get_orders()`, `$product->save()`) rather than `update_post_meta()` or SQL. They keep the product lookup tables, caches, and HPOS order tables in sync.

### Set the Price of Every Product in a Category

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">eval</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">'</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">foreach ( wc_get_products( [ "category" => [ "<CATEGORY_SLUG>" ], "limit" => -1 ] ) as $product ) {</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">	$product->set_regular_price( "0" );</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">	$product->set_sale_price( "" );</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">	$product->save();</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">	WP_CLI::log( "Updated #" . $product->get_id() . " " . $product->get_name() );</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">}'</span>
```

For variable products, the price lives on each variation, so loop over `$product->get_children()` and update each `wc_get_product( $variation_id )` the same way.

### Delete Orders Older Than a Date

This works whether the store uses HPOS or legacy post storage, and processes orders in batches so it doesn't run out of memory:

```
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">CUTOFF</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">=<</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">CUTOFF_DATE</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">eval</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">'</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">$total = 0;</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">do {</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">	$ids = wc_get_orders( [</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">		"type"         => "shop_order",</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">		"date_created" => "<" . getenv( "CUTOFF" ),</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">		"limit"        => 200,</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">		"return"       => "ids",</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">	] );</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">	foreach ( $ids as $id ) {</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">		wc_get_order( $id )->delete( true );</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">	}</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">	$total += count( $ids );</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">	WP_CLI::log( "Deleted {$total} orders so far" );</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">} while ( $ids );</span>
<span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">WP_CLI::success( "Deleted {$total} orders." );'</span>
```

Replace `<CUTOFF_DATE>` with a date like `2023-11-01`. Orders created before that date are deleted. `delete( true )` deletes each order permanently instead of moving it to the trash.

Warning

Don't select order IDs from `wp_posts` or `wp_wc_orders` with SQL and delete them in a loop. With HPOS and compatibility sync, an order exists in both places, and deleting from only one leaves the two out of step. Deleting orders also removes sales history from WooCommerce Analytics.

## Users

### Create an Emergency Administrator

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">user</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">create</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">USERNAM</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">E</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">EMAI</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">L</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--role=administrator</span>
```

Leaving out `--user_pass` makes WP-CLI generate a strong password and print it once, so the password never lands in your shell history. To reset an existing account instead, use `wp user reset-password <USERNAME> --skip-email --show-password`. It changes the password and prints the new one without emailing the user.

Warning

Remove or downgrade emergency accounts when you're done: `wp user delete <USERNAME> --reassign=<OTHER_USER_ID>`.

## Integrity and Reinstalls

### Check for Modified Core and Plugin Files

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">core</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">verify-checksums</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">plugin</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">verify-checksums</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--all</span>
```

Any file listed as changed or unexpected is worth a look, especially after a suspected compromise. Plugins that aren't hosted on WordPress.org report that no checksums are available.

### Reinstall All Plugins

This replaces plugin files with fresh copies at the same version without touching settings:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">plugin</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">list</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--status=active</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--field=name</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">|</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">xargs</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-r</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-n1</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">plugin</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">install</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--force</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">plugin</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">list</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--status=inactive</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--field=name</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">|</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">xargs</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-r</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-n1</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">plugin</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">install</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--force</span>
```

Premium plugins that aren't on WordPress.org will fail. Reinstall those from the vendor's zip. If a broken plugin stops WP-CLI from loading, add `--skip-plugins --skip-themes` to each `wp` call. For memory errors, run WP-CLI with `php -d memory_limit=512M "$(command -v wp)" ...`.

### Reinstall WordPress Core

Removing `wp-admin` and `wp-includes` first clears out any files that were injected into them, then the download restores clean copies of the same version:

```
<span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">VERSION</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">=</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"$(</span><span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069"> core version)"</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">rm</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">-rf</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">wp-admin</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">wp-includes</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">core</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">download</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--version=</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">$VERSION</span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">"</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--skip-content</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--force</span>
```

`--skip-content` leaves `wp-content` (themes, plugins, and uploads) alone. Root-level core files like `wp-login.php` are overwritten, while `wp-config.php` and any extra files in the web root are kept, so inspect leftover root files by hand.

Warning

Capture the version **before** deleting `wp-includes`, because `wp core version` reads it from there.

### Roll Back to an Earlier Core Version

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">core</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">update</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--version=</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E"><</span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">VERSION</span><span style="--shiki-dark:#FF7B72;--shiki-light:#CF222E">></span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#79C0FF;--shiki-light:#0550AE">--force</span>
```

Downgrading core doesn't downgrade the database schema. Roll back only to undo a very recent update, and restore a database backup if the newer version ran a database upgrade the older one doesn't understand.

## Database Checks

`wp db` commands use the credentials from `wp-config.php`, so you don't need a MySQL root login:

```
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">db</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">check</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">      </span><span style="--shiki-dark:#8B949E;--shiki-light:#6E7781"># Run CHECK TABLE on every WordPress table.</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">db</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">repair</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">     </span><span style="--shiki-dark:#8B949E;--shiki-light:#6E7781"># Repair corrupted tables (MyISAM, or InnoDB where supported).</span>
<span style="--shiki-dark:#FFA657;--shiki-light:#953800">wp</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">db</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328"> </span><span style="--shiki-dark:#A5D6FF;--shiki-light:#0A3069">optimize</span><span style="--shiki-dark:#E6EDF3;--shiki-light:#1F2328">   </span><span style="--shiki-dark:#8B949E;--shiki-light:#6E7781"># Reclaim space after large deletions.</span>
```

To check every database on the server rather than just this site's, run `mysqlcheck --all-databases --check` as a MySQL administrator.

See [Database Optimization Queries](/kb/wordpress/database-optimization-queries/) for finding what's bloating the database.

## One-Liner WordPress Migration

Export an entire site:

```
wp db export site-db.sql && tar -czf site-backup.tar.gz . --exclude=site-backup.tar.gz
```

or to zip:

```
wp db export database.sql && zip -r wordpress-site.zip . && rm database.sql
```

XML Content Only (The built-in WXR standard):

```
wp export --dir=. --filename_format="wp-content-export.xml"
```

Sources

- [developer.wordpress.org/cli/commands](https://developer.wordpress.org/cli/commands/)
- [developer.wordpress.org/cli/commands/search-replace](https://developer.wordpress.org/cli/commands/search-replace/)
- [developer.wordpress.org/cli/commands/core/download](https://developer.wordpress.org/cli/commands/core/download/)
- [developer.woocommerce.com/docs/extensions/core-concepts/wc-get-orders](https://developer.woocommerce.com/docs/extensions/core-concepts/wc-get-orders/)
- [docs.litespeedtech.com/lscache/lscwp/cli](https://docs.litespeedtech.com/lscache/lscwp/cli/)

Need help with WordPress?

Our notes can take you a long way, but sometimes you'd rather have someone who's done it before.

[Websites](/services/websites/)

[← PreviousWordPress debugging snippets](/kb/wordpress/debugging-snippets/)[Next →wp-config.php reference](/kb/wordpress/wp-config-reference/)

CC0This article is in the public domain ([CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/)), code samples included. Use it however helps you.

On this page

- [Before You Run Anything](#before-you-run-anything)
- [URLs and Search-Replace](#urls-and-search-replace)
- [Switch a Site From HTTP to HTTPS](#switch-a-site-from-http-to-https)
- [Move a Site to a New Domain](#move-a-site-to-a-new-domain)
- [Bulk Deletion](#bulk-deletion)
- [Delete All Posts of a Post Type](#delete-all-posts-of-a-post-type)
- [Delete All Terms in a Taxonomy](#delete-all-terms-in-a-taxonomy)
- [Pause Cache Purging During Bulk Jobs](#pause-cache-purging-during-bulk-jobs)
- [WooCommerce](#woocommerce)
- [Set the Price of Every Product in a Category](#set-the-price-of-every-product-in-a-category)
- [Delete Orders Older Than a Date](#delete-orders-older-than-a-date)
- [Users](#users)
- [Create an Emergency Administrator](#create-an-emergency-administrator)
- [Integrity and Reinstalls](#integrity-and-reinstalls)
- [Check for Modified Core and Plugin Files](#check-for-modified-core-and-plugin-files)
- [Reinstall All Plugins](#reinstall-all-plugins)
- [Reinstall WordPress Core](#reinstall-wordpress-core)
- [Roll Back to an Earlier Core Version](#roll-back-to-an-earlier-core-version)
- [Database Checks](#database-checks)
- [One-Liner WordPress Migration](#one-liner-wordpress-migration)

[Back to top↑](#top)

Services

- [ERP implementation](/services/erp/)
- [Odoo](/services/erp/odoo/)
- [ERPNext](/services/erp/erpnext/)
- [Custom software](/services/custom-software/)
- [Devices & IoT](/services/devices-iot/)
- [Websites](/services/websites/)
- [Infrastructure](/services/infrastructure/)

Resources

- [Our work](/work/)
- [Open source](/open-source/)
- [Knowledge base](/kb/)
- [Insights](/insights/)

Company

- [About](/about/)
- [Team](/about/team/)
- [Partners](/partners/)
- [Contact](/contact/)

Clients

- [Project portal](https://erp.avunu.net/projects)
- [Invoices](https://erp.avunu.net/)
- [Support](https://erp.avunu.net/)

[![Avunu](/brand/avunu-logo-light.svg)](/)[\<av-icon data-jx-static>\<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor" stroke="none" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">\<path d="M20.400 20.500h-3.600v-5.600c0-1.300 0-3-1.800-3s-2.100 1.400-2.100 2.900v5.700H9.400V9h3.400v1.600c.5-.9 1.600-1.900 3.400-1.900 3.600 0 4.300 2.400 4.300 5.500v6.300zM5.300 7.400a2.100 2.100 0 1 1 0-4.100 2.100 2.100 0 0 1 0 4.100zm1.800 13.100H3.600V9h3.500v11.500zM22.200 0H1.800C.8 0 0 .8 0 1.700v20.600c0 .9.800 1.700 1.800 1.700h20.400c1 0 1.800-.8 1.800-1.700V1.700C24 .8 23.200 0 22.200 0z">\</path>\</svg>\</av-icon>](https://www.linkedin.com/company/avunu)[\<av-icon data-jx-static>\<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor" stroke="none" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">\<path d="M12 .3a12 12 0 0 0-3.8 23.4c.6.1.8-.3.8-.6v-2c-3.3.7-4-1.6-4-1.6-.6-1.4-1.4-1.8-1.4-1.8-1-.7.1-.7.1-.7 1.2.1 1.8 1.2 1.8 1.2 1 1.8 2.8 1.3 3.5 1 .1-.8.4-1.3.7-1.6-2.7-.3-5.5-1.3-5.5-5.9 0-1.3.5-2.4 1.2-3.2-.1-.3-.5-1.5.1-3.2 0 0 1-.3 3.3 1.2a11.500 11.500 0 0 1 6 0c2.300-1.500 3.300-1.200 3.300-1.200.6 1.700.2 2.900.1 3.200.8.8 1.200 1.900 1.200 3.200 0 4.600-2.800 5.600-5.500 5.900.4.400.8 1.100.8 2.200v3.300c0 .3.2.7.8.6A12 12 0 0 0 12 .3">\</path>\</svg>\</av-icon>](https://github.com/Avunu)[Client portal](https://erp.avunu.net/projects)[Start a project](/start/)

Avunu LLC · 948 East Philadelphia Street, York, PA 17403 · (717) 814-8540Knowledge base articles are in the public domain[Privacy](/privacy/)[Terms](/terms/)
