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 columns shows the structure of a WordPress table

WordPress
~/tips/tip-wordpress-db-columns-table

wp db columns wp_postmeta

Lists every column of a table with its type, key and default value.

Before I write a query against a plugin table, I want to know what the columns are called. wp db columns answers that without opening a MySQL client.

wp db columns wp_postmeta

The output is a table with one row per column: Field, Type, Null, Key, Default and Extra. For wp_postmeta you see meta_id as the primary key with auto_increment, and meta_value as longtext. That is the same information DESCRIBE gives in MySQL.

--format=json or --format=csv makes it easy to read in a script. Running it on the same table on two sites shows whether a plugin update changed the schema.

To find the table names first:

wp db tables --all-tables-with-prefix

Mind the prefix. Many installs don’t use wp_, and the command needs the real name, like shop_postmeta. wp db prefix prints the one your site uses. It only reads, so it is safe to run anywhere.

Further reading: wp db columns, wp db tables

More WordPress tips wp user application-password create anna backup-script --porcelain define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size All WordPress tips (85) All topics

Link