[wp-hackers] How to create relations between custom post types?
Edward de Leau
e at leau.net
Sat May 29 22:35:32 UTC 2010
> Like how Mike mentioned below, you setup both the taxonomy and the
> post_type, but turn off the rewrite rules for the taxonomy.
>
> -For the taxonomy, give it a different capability strings so that normal
> users can't add/delete them directly.
> -Use the save_post and delete_post actions to automatically add and delete
> the given term for the custom post
> -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.
> -Like Mike mentioned below, use the post_type's permalink to pull in the
> single-{post_type}.php and display the data from the custom post. But then
> have a query_posts call within that page that pulls in the child posts based
> on the term set in the post's meta field.
thanks! adding and deleting them automatically was what in my mind
because else it would be much work. I'll give it a try to see how this
works out.
" I believe that will become a common design pattern now that we have
custom post types."
I think there are 2 routes:
- either via custom fields which carry the relation but you have to
set all links for yourself.
- or the route via the taxonomy as discussed (advantage=auto linking)
Apart from this solution i was also thinking on another one using
taxonomies: also "tag" the "from" custom post and then give it a
status like "sticky". Then loop the ones and treat the first as
special with some code around it. This is maybe a third one to try.
im going todo some coding :)
More information about the wp-hackers
mailing list