WordPress.org

Ready to get started?Download WordPress

Forums

Hook for trash and untrash of CPTs (2 posts)

  1. drtanz
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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

Tags

No tags yet.