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
wp_posts
table. - Getting post meta (custom fields) in native SQL
get_post_meta()
Prerequisites
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.
If you listen carefully, you can hear the 1s and 0s flowing in your computer.
Episodes
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