[]RSS

About Archives Artwork Comic Contact Philosophy Projects Tags

Listing categories using WordPress 2.3’s new taxonomy system

October 6th, 2007 in Micro Blog

I upgraded to Wordpress 2.3 today, which broke a few of my hacked plugins. The code broke as it relied on the old category system, which was replaced by a new, more flexible, taxonomy system. The new schema is well designed too, and the new queries are much cleaner as a result. Here’s an example of how to get a list of categories1:

SELECT *
    FROM wp_terms AS t 
JOIN wp_term_taxonomy AS tx 
    ON t.term_id = tx.term_id 
JOIN wp_term_relationships AS tr 
    ON tr.term_taxonomy_id = tx.term_taxonomy_id 
WHERE taxonomy = 'category' 
GROUP BY t.term_id
ORDER BY count DESC, t.term_id;

The new taxonomy approach introduces the possibility of displaying better clusters of categories, by including tags in the mix. It also cleans up the SQL from the previous releases with simpler ways of getting count and a clearer relationship mechanism. The table design is clean too, a big improvement over past schemas.

  1. Of course, you would use the public category/taxonomy APIs if this was all you needed

 

Leave a Reply

Subscribe to comments