← ClaudeAtlas

wp-databaselisted

Use when a WordPress plugin needs a custom database table — creating with dbDelta (strict SQL format: two spaces before PRIMARY KEY, no trailing comma), writing versioned upgrade routines with version_compare and register_activation_hook, querying with $wpdb prepared statements (prepare, insert, update, delete, get_row, get_results, get_var), debugging with $wpdb->last_error or SAVEQUERIES, schema migrations between plugin versions, uninstall cleanup, multisite table handling with switch_to_blog / get_sites, or seeding test/preview data into custom tables. Triggers: "create a custom table", "dbDelta not working", "dbDelta not creating my table", "write a migration", "wpdb query", "wpdb prepare", "slow query on my custom table", "upgrade my database schema", "add a column to my table", "seed test data", "how do I store this in a custom table", "database upgrade routine", "table not being created on activation", "prepare placeholder wrong", "last_error is empty after query", "SAVEQUERIES debug", "version_compar
mralaminahamed/wp-dev-skills · ★ 27 · API & Backend · score 77
Install: claude install-skill mralaminahamed/wp-dev-skills
# WordPress Custom Database Tables > **Model note:** `dbDelta` schema and CRUD patterns are mechanical (`haiku`). Query optimisation and multi-version data migrations require cross-file reasoning — use `sonnet` for those sub-tasks. Create and manage custom database tables in WordPress plugins: `dbDelta()` for schema definition, versioned upgrade routines, `$wpdb` CRUD with prepared statements, and data migration strategies. ## When to use - "Create a custom DB table for my plugin", "set up plugin schema with dbDelta". - "Write a migration for plugin upgrade", "run schema changes on update". - "Query a custom table", "insert/update/delete with $wpdb". - "Optimise a slow custom query", "add an index to a plugin table". - "Migrate data from post meta to a custom table". **Not for:** WooCommerce order table operations — use `wp-woocommerce`. General $wpdb query optimisation in core WP tables — use `wp-performance` (official skill). ## Method ### 1. Create table with dbDelta `dbDelta()` is the only WP-safe way to create and alter tables — it diffs the current schema against the SQL and applies only the necessary changes. ```php function my_plugin_create_tables() { global $wpdb; $charset_collate = $wpdb->get_charset_collate(); // e.g. DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci // $wpdb->prefix respects multisite site prefix automatically $table_log = $wpdb->prefix . 'my_plugin_log'; $table_meta = $wpdb->prefix . 'my_plugin_item_meta'