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

Kyle Hotchkiss picture Kyle Hotchkiss · Mar 1, 2011 · Viewed 28.8k times · Source

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.

Answer

mindctrl picture mindctrl · Oct 29, 2013

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' );