Leave a Reply

2 comments

  1. I’m not sure that one can be called categorically faster than the other. And, in any case, it’s only really going to emerge when you start to scale up to many, many objects.

    The issue is this: The postmeta table is a key-value table that is not indexed. If you have a certain number of rows in the table – say, a few hundred thousand – this can begin to cause speed issues, because MySQL has to do a full tablescan whenever you do a query like ...FROM $wpdb->posts WHERE meta_value = 'foo' and meta_value = 'bar'...

    Taxonomy queries, on the other hand, require one or two subqueries. But the tables in question are aggressively indexed (and the queries are cacheable in a nice way) so that these queries perform dramatically better at scale (again, ‘scale’ means many, many thousands of posts).

    As far as “complexity” is concerned – it’s really only a few extra lines of code for register_taxonomy(). The tax_query param for WP_Query is no more complex than meta_query, and the syntax of wp_x_post_terms() is only a bit more complex than x_post_meta(). And I wouldn’t worry about “defeating the purpose of a taxonomy”. The tools are there for you to use however it works best for your project 🙂 And there may come a day when, for some reason, you actually want to have multiple terms per item, in which case the choice of taxonomies would have been a forward-thinking choice.

  2. Is a taxonomy where you can only have 1 term defeating the purpose of a taxonomy in the first place?

    You can change the way it appears in post edit page using metabox to make taxonomy select box, so that only one term is ever selected….

    I think in your case meta query will be more faster than tax query as meta query requires 2 tables to join posts and postmeta, while taxonomy will require three tables posts,taxonomyrelation table and terms table….