Dynamic content requires a storage system to retain the content, settings, and information. WordPress uses MySQL as its relational database. In this hands-on lab, you will dig into the WordPress database structure, do basic raw SQL queries, and learn about the relationship between WordPress and its database.
What You Will Learn
In this hands-on lab, you will be learning about WordPress database, MySQL, and the WordPress functions available to you. More specifically, you will learn:
- Introduction to relational databases, records, rows, columns, and more
- Database table structure and intent
- Table definitions
- Getting posts in native SQL
- Introduction to how WordPress fetches posts from the
- Getting post meta (custom fields) in native SQL
You need to have a sandbox test site spun up and ready to go. If you need help with it, see the Setting Up Your Sandbox Test Website article in our Help Center. Make sure you turn on the debug mode in your
wp-config.php file. The code is in that same Help Center article.
In order to do this lab, you will need the following:
- A local web server, such as Local by Flywheel, Desktop Server, MAMP, WAMP, VVV, or some other application.
- Your favorite IDE or editor. (Tonya uses PhpStorm.)
- Firefox and/or Google Chrome
- A database interface such as Sequel Pro (which is what Tonya uses) or phpMyAdmin.
Code. Eat. Code. Sleep. Dream about Code. Code.
Total Lab Runtime: 02:08:59
- 1 Lab Introductionfree 05:17
- 2 The Big Picturepro 14:35
- 3 Your First SQL Querypro 12:21
- 4 WordPress to Database Relationshippro 20:20
- 5 Filter Content with WHEREpro 08:24
- 6 Table Alias with ASpro 05:08
- 7 Defining Table Structure (Schema)pro 12:17
- 8 Create a New Database Tablepro 10:23
- 9 WordPress Schemapro 05:11
- 10 Exploring WordPress Queries with Query Monitorpro 07:14
- 11 SQL to Get a Custom Fieldpro 16:41
- 12 SQL to Update Custom Fieldpro 05:14
- 13 Wrap it Upfree 05:54
This hands-on lab teaches you more advanced SQL including table relationship types, how to join multiple tables together, and how to write SQL queries that are faster and more scalable for your WordPress projects. You will use a practical example plugin to test two different approaches to solving the problem of fetching posts that are grouped by each term. You'll test these approaches, explore the actual SQL queries, and learn about the impact of processing speed, performance, and scalability.
Check out the SQL Library for more hands-on labs, insights, Docx, and more.