[wp-hackers] Mirroring a custom_post to a custom_taxonomy for post2post relation [was: Time for a wp_post_relationships table?]
Lox
lox.dev at knc.nc
Tue Aug 3 19:58:36 UTC 2010
Otto,
Taking the following case:
- two custom post types (movies and actors) and a custom taxonomy actors.
- the actors taxonomy should contains all actors created through the
actors custom post type admin ui, not more, not less.
- then, actors term can be applied to any movie. This gives the
ability to retrieve all movies where an actor plays in, or, all actors
of a specific movie.
2010/8/4 Otto <otto at ottodestruct.com>:
> It's not really all that hard to do, you simply add the term to the
> post with wp_set_object_terms when the post is published, and perhaps
> modify it when the post is edited
Taking an actor creation. When the actor get created (save_post hook)
I apply a term in actor taxonomy with the actor post title as the
term, using wp_set_object_terms ?
When it is a post update, I need to update the taxonomy using wp_update_term ?
So basically, I add an action 'save_post' where I check:
- if post type is actor
- if it is a post update or a post creation
- act accordingly
Is that it?
> (delete will be handled
> automatically, as when a post goes away, so does it's relationship
> with its terms).
Not automatically: if an actor get deleted, the related term in actors
taxonomy could also have been applied to one or more movies, and thus
won't be deleted
> You can probably use transistion_post_status to
> handle both of those.
transistion_post_status ? Is that an action hook? If so it is undocumented...
--
Lox
lox.dev at knc.nc
More information about the wp-hackers
mailing list