Let’s run the fast approach tests. You’ll look at the SQL queries using Query Monitor as well as the data dumps you put into Core. We’ll talk about the code, how it works, and ways that you can enhance it for more versatile use cases. Then we’ll compare the two approaches.
Here’s a code challenge for you. Convert the SQL function
Wrap it Up
Congratulations! You did a great job.
We covered a lot of information in this lab including learning about database table relationships, how to join tables together, filtering down to what you need, aliasing the columns you get back, performance, scalability, and how to build a SQL query. You also learned about
$wpdb->get_results(). Whew! That’s a lot in one lab.
What you learned in this lab is how to build custom SQL queries that are performant and scalable. The use cases are endless as to how you can use this information. In this lab, we queried the database to fetch the posts grouped by terms in one database hit. Other use cases include:
- Fetching custom post types by a specific term
- Quering events by a range of dates for say a site that tracks conferences, parties, appointments, or other events
- Fetching specific user metadata information say from a membership site or custom portal
Learning how to build specific SQL queries unlocks the possibilities for you. The database holds the content. In this lab, you saw all the different tables and relationships. By building custom queries, you can build more performant and scalable solutions for your clients.WooHoo! I've leveled up to master advanced #SQL for #WordPress. Click To Tweet
You did it! Excellent job! Bam, you’ve now unlocked your potential to build advanced queries to get the datasets you need for you projects. WooHoo! Way to go.
Code. Eat. Code. Sleep. Dream about Code. Code.
Total Lab Runtime: 02:46:48
- 1 Lab Introductionfree 14:27
- 2 Slow Approach Overviewpro 12:11
- 3 Test Slow Approach - Part 1pro 17:27
- 4 Test Slow Approach - Part 2pro 21:07
- 5 Relational Typespro 23:20
- 6 Types of Joinspro 09:30
- 7 Joining Metadatapro 12:37
- 8 Joining Posts to Termspro 20:32
- 9 Grouping Datasetspro 08:32
- 10 WordPress SQL Handler $wpdbpro 11:01
- 11 Deeper Dive into $wpdb->get_resultspro 05:54
- 12 Run Fast Approach & Compare Resultspro 10:10