Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm building a portfolio post type and I want to have a way to mark certain pieces as featured, some as normal (default) and others as archived. The pieces would only ever be one of these 3. Because of the singular value it makes sense to me that this be post meta. But, i've read that querying by taxonomy is supposedly faster, so I've built a solution where featured, normal and archived are 3 terms in a custom taxonomy.

Should I stick with the taxonomies for this case, or switch to post meta. I realize that is an opinion question, so to make it more specific: is the query speed improvements worth the added complexity of creating a custom taxonomy and modifying it so that it can only ever have 1 term? Is a taxonomy where you can only have 1 term defeating the purpose of a taxonomy in the first place?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
well i have the taxonomy set up already... i just need convincing to not monkey with code that is working! ha. so at huge scale this might make a difference, but otherwise unnoticeable? –  helgatheviking Apr 6 '12 at 21:37
    
Yes. If you already have it set up, leave it. I can't think of any arguments for switching it to postmeta. –  Boone Gorges Apr 6 '12 at 21:38

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

share|improve this answer
    
thanks for the answer! i already have a metabox that selects a single term for a taxonomy. there's no actual data available on the speeds is there? –  helgatheviking Apr 6 '12 at 21:38
    
I once tried to test this out since I (ab)use categories for a similar task (asides v. full posts) and it causes me no end of woes. The results were complicated and unconvincing when testing with my real, enormous database (70k posts). –  jeremyclarke Aug 20 '12 at 23:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.