[wp-hackers] How to create relations between custom post types?
mpretty at voceconnect.com
Sun May 30 03:52:33 UTC 2010
>> -Link the custom post to its term by storing the term_id in the post_meta of the post. We've learned that trying to match them up via slug/post_name fields becomes a nightmare due to conflicts.
> Really? I'd love to hear some elaboration on that so I'll know what issues to look out for.
I was implementing this for a radio station. The specific post type
that needed to be created were individual shows. They needed a way to
associate posts with those shows, so there was a show taxonomy and each
show had it's own term. I first attacked the problem by trying to make
the show term that represented each show have the same slug as the show
did. The issue we had with this was when the client would create more
than one copy of the same show with the same title. Only one would be
published, but they would have a copy sitting in draft or in the trash
for some reason or another. When this happened, it was often the show
in the trash or in draft that would be the one that was created first,
and in turn, it would get the term that matched the name of the show.
This would cause the show that was actually published to end up creating
a term that had a slug of "the-show-title-2" instead of
"the-show-title". So then when we tried to get the matching term based
on the show's post_name, it didn't match up because of the -2. There
were similar issues if the name of a show was changed.
More information about the wp-hackers