[wp-hackers] How to create relations between custom post types?

Edward de Leau e at leau.net
Sat May 29 06:49:43 UTC 2010


How can I create relations between custom post types?
------------------------------------------------------------------------
A Case: In the game FarmVille there are so called mysteryboxes.
A mysterybox contains objects e.g. buildings, animals, etc...
------------------------------------------------------------------------
1. I have created custom post types for buildings and animals
2. I have created a custom taxonomy called "mysterybox"

result: I can now pick one or more mysteryboxes with e.g. a building
(custom post type) so
that i can see in which mystery boxes that building was present.

If i now do http://myblog/mysterybox/mystery-box-1 I get all the
buildings, etc... for that box good!
If i now do http://myblog/mysterybox I get nothing as expected

so works perfect.

------------------------------------------------------------------------
The problem: A Mysterybox in itself it also a custom post type it also
has custom fields
like date, cost etc...

So I tried creating a custom post type named "mysterybox" and a "post"
named "Mystery Box 1",
which works. (so the custom post type name is identical to the custom
taxonomy name)

If i now do http://myblog/mysterybox/mystery-box-1 the taxonomy takes
however preference,
i do not see the contents of my custom post even if i create a
single-mysterybox.php, I
would expect to see the content of my custom post at the top and after
that the list of
posts that carry the identical taxonomy term.

If i now do http://myblog/mysterybox i would at least expect to see
the list of posts but
that also shows nothing (while it does with http://myblog/building)
------------------------------------------------------------------------
would it be possible to support cases where a custom post type and a
custom taxonomy type carry
the same name? I think they do not conflict.

(It enables creating relations between custom post types).


Another case would be where there is a custom post type "Address" and
a custom post type "Contact".
If every contact and every address is also a custom taxonomy of the
same kind I can choose contacts with addresses and
addresses with contacts (both N:M).




-- 
Edward de Leau
http://populair.eu


More information about the wp-hackers mailing list