Skip to main content

SQL Queries, PHP Code, and Subcommands with WP-CLI

Learn how to run SQL queries, PHP code, and subcommands on WP-CLI.


This section provides information on how to run SQL queries, PHP code, and subcommands on WP-CLI.

Run SQL Queries Using WP-CLI on Pantheon

Use echo to pipe (or redirect) a SQL query through WP-CLI via Terminus:

echo "SELECT * FROM wp_users WHERE ID=1;" | terminus wp $site.$env -- db query

Execute PHP Code Using WP-CLI on Pantheon

The wp eval command is not supported on Pantheon, but you can still run the interactive shell wp shell to execute PHP commands:

terminus wp $site.$env -- shell
var_dump($_ENV);

Extending WP-CLI With Subcommands

WP-CLI has a framework for users to write their own commands. Learn about the anatomy of a subcommand to solve problems with WP-CLI.

WP-CLI commands are subject to platform PHP memory limits, which are optimized for serving webpages and not necessarily for running development tools. We recommend that you run Composer commands, such as wp package install, on your local machine or on a CI service.

More Resources