Unlock your potential with a Pro Membership
Here is where you propel your career forward. Come join us today. Learn more.
Joining Posts to Terms
Lab: Advanced SQL – Get Posts Grouped by Terms
Video Runtime: 20:32
It’s time to write the native SQL query that glues the taxonomy to the terms and then the terms to the posts. In this episode, you will write SQL in phpmyAdmin or Sequel Pro. We’ll go step-by-step, first fetching terms for the category taxonomy. Then we’ll filter our query to get terms only for certain post IDs. Then you’ll join in the posts database table and select specific content out of each.
Did you know?
Did you know that you can change the keys that are sent back to you from a query? Yup, using the alias keyword AS
, you can change a column to be a specific alias. For example, when fetching a post ID out of the wp_term_relationships
, the column is actually named object_id
. That will be confusing when it’s returned back with the query. You can change it to be post_id
:
SELECT tr.object_id AS post_id
Code. Eat. Code. Sleep. Dream about Code. Code.
Episodes
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