Hook for trash and untrash of CPTs (2 posts)

  1. drtanz
    Posted 3 years ago #

    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.

  2. Xiphe
    Posted 2 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.