wp_trash_post_comments example

$post_updated = wp_update_post(
        array(
            'ID'          => $post_id,
            'post_status' => 'trash',
        )
    );

    if ( ! $post_updated ) {
        return false;
    }

    wp_trash_post_comments( $post_id );

    /** * Fires after a post is sent to the Trash. * * @since 2.9.0 * @since 6.3.0 Added the `$previous_status` parameter. * * @param int $post_id Post ID. * @param string $previous_status The status of the post at the point where it was trashed. */
    do_action( 'trashed_post', $post_id$previous_status );

    
/** This action is documented in wp-includes/post.php */
        do_action( "save_post_{$post->post_type}", $post->ID, $post, true );

        /** This action is documented in wp-includes/post.php */
        do_action( 'save_post', $post->ID, $post, true );

        /** This action is documented in wp-includes/post.php */
        do_action( 'wp_insert_post', $post->ID, $post, true );

        wp_after_insert_post( get_post( $post_id ), true, $post );

        wp_trash_post_comments( $post_id );

        /** This action is documented in wp-includes/post.php */
        do_action( 'trashed_post', $post_id );

        return $post;
    }

    /** * Handles request to trash a changeset. * * @since 4.9.0 */
Home | Imprint | This part of the site doesn't use cookies.