[wp-hackers] Specific hooks for working with custom post types?

Simon B piemanek at gmail.com
Sun Mar 28 13:19:56 UTC 2010


No, I don't need wp_insert_post because I am doing something when a post is
being saved. Here's a clarification:

I've got a meta box on my custom post type edit screen (called using
register_meta_box_cb from within register_post_type), with various fields
into which the user enters metadata.

So when "Publish" or "Save Draft" is clicked, I'm hooking into save_post to
save that data as postmeta. I've used this general idea in loads of sites,
but only now looking into using custom post types.

I was asking because I may want to do different things when the post saves,
depending on the post type.

Hope that makes it a bit clearer!
Simon


On 28 March 2010 14:03, Mike Schinkel <mikeschinkel at newclarity.net> wrote:

> On Mar 28, 2010, at 8:39 AM, Simon B wrote:
> > I've been learning my way round all the great new support for custom post
> > types in WordPress 3.0, but just wondering if there are plans to make
> > specific hooks available, for example when saving a custom post type?
> >
> > Say I have a custom post type called "case-study", will there be a hook
> > "save_case-study" (and "delete_case-study", etc)?
> >
> > If not, what's the best way to check the type of the current post?
> >
> > At the moment I hook into save_post then check the post type like this:
> >
> > if ( 'case-study' == $_POST['post_type'] ) {
> >    # save case-study meta...
> > }
> >
> > but not sure if this is the best method.
>
>
> In what context are you planning to use this?  Why are you wanting to use
> $_POST?
>
> I think what you need would be this:
>
> add_action('wp_insert_post','my_wp_insert_post');
>
> function my_wp_insert_post($post_id,$post) {
>        if ( 'case-study' == $post['post_type'] ) {
>                # save case-study meta...
>        }
> }
>
> Is this not what you need?
>
> -Mike
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list