brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: wp db search finds a string anywhere in the WordPress database

Database
~/tips/tip-wordpress-db-search-string

wp db search example.com

Searches every WordPress table for a string or regex and shows the table, column and row.

After a domain change or a plugin removal I always wonder what is still pointing at the old address. wp db search answers that by looking through every table WordPress knows, so I do not have to guess which one holds the leftover.

The basic form takes just the string:

wp db search example.com

It prints the table and column, the row ID, and a bit of text around each match (40 characters either side by default). The search is case-insensitive. Narrow it to one table by naming it after the string, or add --stats to see how many rows and columns it went through and how long it took.

For patterns there is --regex:

wp db search 'https?://' --regex --stats

A regex search is case-sensitive, and it runs per column, so anchor with ^ and $ when you want the whole value to match.

The caveat is scope. By default it only covers tables registered to $wpdb. Tables from a plugin that are not registered that way are skipped, and --all-tables-with-prefix or --all-tables widen the search at the cost of runtime and some unexpected hits. On a big database expect it to take a while. The docs show a run across about 1.36 million rows that needed roughly ten seconds.

This command only reads, so it is safe. If you plan to replace what it finds, look at wp search-replace next and use its dry run first.

Further reading: wp db search (WP-CLI handbook)

More Database tips mariadb -e 'CREATE DATABASE IF NOT EXISTS blog' mariadb-dump --no-create-info --insert-ignore shop orders > orders-rows.sql SELECT table_schema, table_name, CHECKSUM TABLE shop.orders; services: All Database tips (53) All topics

Link