[wp-hackers] custom post types: order by taxonomy

Otto otto at ottodestruct.com
Tue Mar 8 00:04:30 UTC 2011


On Mon, Mar 7, 2011 at 5:43 PM, Mark E <mark at simplercomputing.net> wrote:
> On 03/07/2011 01:31 PM, Otto wrote:
> I'm well aware of why taxonomies exist. I didn't provide enough info in the
> original post, and I've since did some testing. Here's a pseudo scenario:
>
> Example: post type is music; taxonomies are genre, artist, and label.

I'd say that genre would be good as a taxonomy. Artist and label could
go either way, but postmeta would make more sense for them, IMO. To
each his own, obviously.

> The problem arises when querying
> for posts by taxonomy, because some posts are missing a taxonomy setting
> (e.g. no label defined). If I use tax_query to get a list of posts in the
> label taxonomy then any posts that don't have the label set are not show.
> That isn't the desired result.

True, but it's one of the aspects of using a taxonomy. If you don't
have a particular item grouped in a taxonomy, then query based on that
taxonomy, obviously you're not going to get that item back.

> So I have to dream up some other way to deal with that problem without
> forcing someone to always set terms in all 3 taxonomies.

This may be why postmeta is a better choice for your situation. If you
had "label" as the "key" in post meta, then the postmeta of "label"
would still exist even though its value was empty.

The important thing about taxonomies is that the terms themselves are
without meaning. It's just a label. Now, we tend to assign it meaning,
but really, it's just a label for a grouping. The important part about
a taxonomy is the grouping of posts created by it, not the meaning
assigned to the term by your brain
.
In other words, a "term" is not actual information, it's just a label
for the group of posts that the term is applied to. When you start
treating it as information-by-itself, then that's when you run into
these kinds of problems. Information should be stored as values, not
as keys. The term is really a key, not a value.

> In a general CMS type of scenario, the WP taxonomy system is a what it is,
> and if it can be used to handle content objects in the desired fashion
> (including any associated UI needs) then it works. And if not, maybe post
> meta is better, or maybe a new table is better.

You're not limited to the UI's provided. If you want to make a meta
box, then add_meta_box is pretty straightforward. You can put in text
boxes that say "Artist:" and "Label:" in front of them, then save the
resulting data to the postmeta yourself. It's easy enough to do.

Using a taxonomy just because it gives you some free UI is silly when
the UI is like 20 lines of code to create.

-Otto


More information about the wp-hackers mailing list