Save_post为自定义帖子类型?


31

是否有用于自定义帖子类型的save_post挂钩?

例如:save_my_post_type

我知道这里有publish_my_post_type,但我正在寻找保存钩子。

Answers:


28

钩子是一样的,save_post只是确保它是您的帖子类型,例如:

add_action('save_post','save_post_callback');
function save_post_callback($post_id){
    global $post; 
    if ($post->post_type != 'MY_CUSTOM_POST_TYPE_NAME'){
        return;
    }
    //if you get here then it's your post type so do your thing....
}

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.