Archives for August 2014

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:

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.

987247c07f002

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 book.

Professional WordPress Third Edition is Coming!

That’s right, the highest rated WordPress development book on the market is back with an all new third edition! The writing has begun and Professional WordPress 3E has officially passed the halfway mark. Just like the previous edition, this version will be written by David Damstra and myself.

Professional WordPress 3E will be fully updated for WordPress 4.1. The new edition will feature two completely new chapters:

  • Migrating to WordPress – Covers understanding the migration process, generating data mapping guides, and utilizing WP-CLI with migration scripts.
  • Application Framework – Covers using WordPress as an application framework, integrating APIs, external libraries, and web services. Will also touch on native app development on iOS and Android.

As an extra special bonus, we have THE Lisa Sabin-Wilson on board as the Technical Editor for this edition! Lisa is the For Dummies brand franchise author on all things WordPress. She has been working with WordPress since 2003 and writing about WordPress since 2006. Lisa is an amazing asset to have on Professional WordPress and will help make this edition the best one yet!

The book is targeting an end of year release. You can follow our progress and any Professional WordPress Third Edition news with the hash tag #prowp3.