Understanding WordPress Taxonomy Table Relationships

## Metadata
- Author: [[Brad Williams]]
- Full Title: Understanding WordPress Taxonomy Table Relationships
- Category: #articles
- Summary: When working with taxonomies in WordPress, it’s helpful to understand the taxonomy database schema. The WordPress database contains three tables for storing taxonomy data: Let’s look at an example database query joining the taxonomy tables.
- URL: https://strangework.com/2014/08/08/understanding-wordpress-taxonomy-table-relationships/
When working with taxonomies in WordPress, it’s helpful to understand the taxonomy database schema. The WordPress database contains three tables for storing taxonomy data:
* **wp\_terms** – stores all of your taxonomy terms
* **wp\_term\_taxonomy** – defines what taxonomy each term belongs to
* **wp\_term\_relationships** – cross-reference table that joins taxonomy terms with your content
Let’s look at an example database query joining the taxonomy tables. The below query will return all posts with all taxonomy terms assigned to each post:
| | |
| --- | --- |
| 123456 | `SELECT` `wt.``name``, p.post_title, p.post_date` `FROM` `wp_terms wt``INNER` `JOIN` `wp_term_taxonomy wtt` `ON` `wt.term_id = wtt.term_id``INNER` `JOIN` `wp_term_relationships wtr` `ON` `wtt.term_taxonomy_id = wtr.term_taxonomy_id``INNER` `JOIN` `wp_posts p` `ON` `wtr.object_id = p.ID``WHERE` `p.post_type =` `'post'` |
Using joins you can start to understand the relationship between the three taxonomy tables. I’m a visual person, so I created the below graphic to illustrate the taxonomy table relationships.
[](http://strangework.com/wp-content/uploads/2014/08/987247c07f002.png)
Taxonomies are an extremely powerful component of WordPress. Understanding the taxonomy database schema can be very helpful when building more complex WordPress websites. If you are interested in learning more about taxonomies in WordPress, check out my [Professional WordPress](http://bit.ly/prowp2) book., Understanding WordPress Taxonomy Table Relationships, Brad Williams, 01gnmd0jgjjqxdaef0evnbhfwd.