[wp-hackers] Time for a wp_post_relationships table?

Otto otto at ottodestruct.com
Tue Aug 3 15:37:02 UTC 2010


On Tue, Aug 3, 2010 at 3:05 AM, Mike Schinkel
<mikeschinkel at newclarity.net> wrote:
> Why would we want to devise their own methods rather than use a standard approach built into core?  (It's an honest question.)

Two reasons.
1. Competition breeds better solutions.
2. The generic case is not a good fit for all use cases.

> You are getting too use-case specific; they don't need to specify what the relationships mean only that they are related. Plugins can add the "meaning" layer but WordPress should probably offer the core relationship support.

The relationships have to be meaningful for there to be
interoperability between differing implementations.

> I think maybe I simply value standardization as a stepping stone for greater things and you don't (right?) and that difference in how we value standardization colors any discussion we have related to it.

I think standardization is a good thing, but the standard must be
well-defined and have a well-defined purpose for it to be useful. This
particular case just seems very vague and hand-wavy to me.

> The use-cases for post-to-post are probably not very apparent when using WordPress only as a blog but become much more apparent when one starts using it as a CMS with lots of different data types.  I'll give you numerous examples where I've needed it in the past several months (#1 thru #3 are actual projects I've worked on, #4 & #5 are hypothetical):
>
> 1.) A law firm website has attorneys, practice areas, articles, case studies, and events/presentations.  Each attorney is in one or more practice areas.  Each article and each case study can be attached to one or more attorneys and relevant to one or more practice areas.  Each event/presentation can have one or more attorneys presenting and can be represented one one or more practice areas' calendars.
>
> 2.) A conference website can have sessions, sponsors, presenters, time slots and rooms. A session can have one or more presenters and be presented in one or more time slots and one room per time slot ,and a presenter can represent a sponsor or not.
>
> 3.) A website listing restaurant menus can have restaurants, locations, menus. A restaurant can have one or more locations and one or more menus (breakfast, lunch, dinner, catering, etc.) A menu can apply to all locations for a restaurant or only a specific location.
>
> 4.) A movie website could have movies and person-roles where a person-role could be an actor, producer, cinematographer, casting, film editing, costumer, set designer, composer, etc.
>
> 5.) A hospital website has doctors and departments.  Each department can have multiple doctors and each doctor can work in multiple departments.
>
> 6.) A radio station website could have stations and disc jockey's where a station could have multiple disc jockeys and each disc jockey could appear on multiple stations (given how radio works these days.)

I don't see how any of these relate to a table which relates posts to
taxonomies (and to each other). Posts get related to terms inside
taxonomies, not to taxonomies themselves.

The cases above seem like you want to be able to relate terms in one
taxonomy to terms in another taxonomy, not to relate posts to whole
taxonomies. IN which case I'd say your initial definitions for what
constitutes a post vs. a term are wrong. If you do want to make
something where a "thing" has both a post and a term for that thing,
then you should do it with a custom post type and tie the term from
the taxonomy to it. Let's consider a simple case of photo management.

Photos are posts (attachments in our specific case, but let's just say
"photos"). They have people in them. Every person is a term in the
"people" taxonomy.
But people have other information about them too. So we make a
"people" custom post type to hold them. Maybe a bio, avatar, etc. To
associate the person to the taxonomy, we simply give that post of them
in "people" the term in the "people" taxonomy, thus relating the two.
So now, if I'm looking at a photo, I can see a list of the people in
the photo by looking at the terms in the people taxonomy. Click on one
of those and I can see all the posts associated with that person. Only
one of those posts is of the "people" type, and that's the one that
gives more information about that person.

My point is that posts should connect to terms, and relate to other
posts by virtue of having the same terms in a taxonomy, even across
post-type  boundaries. This is a much more flexible way of connecting
posts to other posts based on specific shared characteristics.

For your lawyer example (first one):
Post types: attorney, article, case study, event.
Taxonomies: attorney, practice area.

Any of those post types can have terms attached to it from both
taxonomies. There's a specific restriction (in your plugin code) to
only allow one attorney post type per attorney term and only one
attorney term in each attorney post type.

The way you seem to want to do it is to have a whole taxonomy for each
attorney (I think), which is difficult and makes little sense to me. A
taxonomy is general, a person is specific.

> It's not the number of post relationships that a *specific* post has, it's the *total* number of records with the matching meta_key in the wp_postmeta table.

Actually, it is. The postmeta table is indexed by post_id too. If
you're searching through postmeta, you should always be tying to a
specific post.

You are correct that postmeta is a crap way of relating posts to one
another. But that is exactly what taxonomies and terms were designed
to do. I think that because you're defining things as a term instead
of a post type (or vice-versa), I think you're ending up with a
distorted view of what the necessary queries should be.

In your movie example, a movie would be a post type. So would an
actor. These would hold info about them. But they'd both also be
taxonomies (movie and actor). How would the two different items be
related? Term_relationships. A Movie post type would have actors
assigned to it as terms related to it. And it'd have one term from the
movies taxonomy related to it as well. An actor would be reversed,
he's in a bunch of movies (and so is tagged with all those movie
terms), and he's an actor (and so has his actor term tagged to him
too).

This particular case involves no postmeta, because it's using terms
the way they were meant to be used. Terms are there to relate
different posts together in a way that has meaning (by virtue of them
all being in a specific taxonomy). And this meaningful relationship
can be done via many different ways, including many to many.

-Otto


More information about the wp-hackers mailing list