Unlock your potential with a Pro Membership
Here is where you propel your career forward. Come join us today. Learn more.
WordPress SQL Handler $wpdb
Lab: Advanced SQL – Get Posts Grouped by Terms
Video Runtime: 11:01
We have our SQL query that we want to use for our project. Let’s talk about how to translate that into WordPress. How does WordPress communicate with the database? What tools are available?
WordPress provides you with a set of tools to communicate with the MySQL database. This wrapper will save you time and lots of lines of code. The object you’ll use is the global
$wpdb. At the time this lab was developed, WordPress does not provide a wrapper for this global object. Therefore, we have to use the global directly.
In this episode, you’ll explore a couple of functions within this tool:
prepare()– Protect queries from SQL injection attacks
get_results()– Runs a general SELECT SQL query to get datasets
Once upon a time, there was a developer... You! This is going to be a good story...
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