Let’s continue testing the slower approach. In this episode, you will explore the SQL queries when running each WP_Query. This is a fun one. You’ll discover how many queries are generated (i.e. how many times the code hits the database). Then you’ll change the term assignments to discover how the number of queries increases exponentially with the number of terms.
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. 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 […]
Let’s look closer at WordPress Core for the object $wpdb->get_results(). You’ll see that it’s a wrapper for the PHP constructs: mysql_query – PHP 5.5 or less (it’s been removed from PHP 7) mysqli_query – PHP 5 and 7 We’ll also discover that WordPress provides a filter event where the $query is exposed. This event is named “query.” We’ll convert our plugin to remove the snippet from get_results and build a callback for the “query” event. You can use this callback whenever you need to analyze or customize a query. You’ll also do a quick overview of the fast approach code.
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 […]
This hands-on lab is more advanced. It will teach you about more advanced SQL commands, such as JOIN and GROUP BY. You’ll also experiment with $wpdb, which is WordPress’ MySQL Communication wrapper. In this episode, let’s get you ready to start this lab. You’ll learn about the objectives and what you’ll be doing, as well as getting your sandbox ready to go. To get started, you are going to want to install this lab’s companion plugin into your Sandbox project. This plugin is freely available on GitLab. Just follow the instructions in the video (or the README.md) to install. Next, […]
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.