What action can I use in WordPress that triggers whenever a custom post is saved or updated?

后端 未结 2 889
陌清茗
陌清茗 2020-12-30 05:48

Any way to have save_post for custom posts only? The way my functions.php is coded is tacking on lots of custom fields to normal posts and pages who don\'t need/use them.

2条回答
  •  遥遥无期
    2020-12-30 06:13

    WordPress 3.7 introduced a new way of handling this with the save_post_{$post_type} hook.

    Let's say your custom post type is "member-directory". You can now run save_post on that post type only by using something like this:

    function my_custom_save_post( $post_id ) {
    
        // do stuff here
    }
    add_action( 'save_post_member-directory', 'my_custom_save_post' );
    

提交回复
热议问题