Support » Fixing WordPress » Hook for trash and untrash of CPTs

  • How can I hook into the trashing and untrashing of custom post types and execute my functions? I only want my functions to run on a trashing or untrashing of a specific custom post type.

Viewing 1 replies (of 1 total)
  • It seems to be a little inconsistent but this works fine for me:

    Trash hook

    add_action( 'trash_[custom]', 'my_trash_callback' );
    function my_trash_callback( $postID ) {
        // Party hard!
    }

    Untrash hook

    add_action( 'untrash_post', 'my_untrash_callback' );
    function my_untrash_callback( $postID ) {
        if ( get_post( $postID )->post_type === '[custom]' ) {
            // Party hard!
        }
    }

Viewing 1 replies (of 1 total)
  • The topic ‘Hook for trash and untrash of CPTs’ is closed to new replies.