From the course: WordPress: WP-CLI

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Querying the database

Querying the database - WordPress Tutorial

From the course: WordPress: WP-CLI

Start my 1-month free trial

Querying the database

- [Instructor] Executing My SQL queries is core functionality for working from the command line and WP-CLI makes doing it on a WordPress site even easier. The beautiful thing about using WP-CLI is we don't have to worry about connecting separately to the SQL command line interface. WP-CLI handles the connection stuff through the wp config file. Now, most of the information we'd want to get we can likely we do through some of the other WP-CLI functions. Here's an example. If we type wp db columns wp_posts, we can get a list of the fields in the table. Then we can query the database with wp db query and an SQL statement. So I could say SELECT ID, post_title, and post_date FROM wp_posts WHERE post_type=post ORDER BY ID DESC LIMIT 0.20 and that will return a list of post titles, IDs, and dates. Using wp post list might've been a lot easier, but let's say we wanted a table of all of the post meta with the associated ID…

Contents