Run a database query
execute_sql_queryRun single SQL queries on a WordPress database with enforced row limits and mutating statements blocked until preview confirmation. Use when REST API and WP-CLI cannot access the data.
Instructions
Run a SQL query against the WordPress database through the companion plugin. SELECT/SHOW/DESCRIBE/EXPLAIN run immediately with an enforced row limit. Anything that mutates data is blocked unless you pass allow_mutation: true, and even then it first returns a preview and a confirm_token that you must echo back — stacked statements are always refused. Reach for this only when the REST API and WP-CLI cannot get at the data: raw SQL bypasses WordPress hooks, so caches are not invalidated and plugin logic does not run.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | A single SQL statement. Use the site's real table prefix — get it from site_info if you are unsure it is wp_. | |
| site_id | No | Which configured WordPress site to act on. Optional — with a single site configured it is used automatically; with several, the default site is used unless you name one. Run list_sites for valid ids. | |
| max_rows | No | Row ceiling. A LIMIT is appended automatically to unbounded SELECTs. | |
| confirm_token | No | Token returned by the preview, required to actually run a mutating statement. | |
| allow_mutation | No | Permit a data-changing statement. Still requires a confirm_token from the preview. |