What hook gets called when I edit or publish a custom post type of name 'episode gallery' ?

I tried following but none worked.

add_action('save_post', 'update_custom_ngg_table');
add_action('update_postmeta', 'update_custom_ngg_table');
add_action('publish_post', 'update_custom_ngg_table');
add_action('edit_post', 'update_custom_ngg_table');
add_action('edit_page', 'update_custom_ngg_table');
add_action('publish_page', 'update_custom_ngg_table');
add_action('save_page', 'update_custom_ngg_table');
add_action('publish_episode-gallery', 'update_custom_ngg_table');

I am about to give up :)

4 Answers 4


Unless I misunderstand your question, you want {$new_status}_{my-custom-post-type}

Take a look at the hook registration.

This page (from Pippin's Posts)* does a better job than I could at explaining it, but from your example, you would want add_action('publish_episode-gallery', 'update_custom_ngg_table');

According to the source, the following status are available: publish, future, draft, pending, private, trash, auto-draft and inherit.

* Mirror at the Web Archive


It's always save_post, no matter what the post type. save_post also runs when creating and publishing a new post.

From inside your hooked function you can figure out what kind of post is being handled--it gets passed both the post id and the entire post object.

function wpsx_5688_update_post($post_id, $post) {

    // Make sure the post obj is present and complete. If not, bail.
    if(!is_object($post) || !isset($post->post_type)) {

    switch($post->post_type) { // Do different things based on the post type

        case "episode-gallery":
            // Do your episode gallery stuff

        case "another-post-type-slug":
            // Do other stuff

            // Do other stuff


add_action('save_post', 'wpsx_5688_update_post', 1, 2);

Another thing to consider is that--depending on your exact problem, I'm not sure what you're trying to do--it might not be that the hook isn't firing, but that the code inside your hooked function has errors. Just something else to check if you're stuck.


If you want to perform an action when any custom post Edit/insert-

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

If you want to make a change to a specific post type, you can also use the save_post_$this->post_type hook documented here.

$post_type = "enter_your_post_type_name_here";
add_action( 'save_post_' . $post_type, function( $post_id, $post, $update ) {
    // Anything inside this function will run when the specified post type is updated.
} );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.