wp_delete_post_revision()
Deletes a revision.
Deletes the row from the posts table corresponding to the specified revision.
Hooks from the function
Return
WP_Post|false|null
. Null or false if error, deleted post object if success.
Usage
wp_delete_post_revision( $revision );
- $revision(int|WP_Post) (required)
- Revision ID or revision object.
Examples
#1 Delete revision with ID = 7
$rev = wp_delete_post_revision( 7 ); if ( $rev ){ // revision deleted successfully } else { // no such revision was found }
#2 Delete all revisions of the specified post
global $wpdb; $postid = 5; // get all the revisions of the post $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) ); foreach( $revision_ids as $revision_id ){ wp_delete_post_revision( $revision_id ); }
Changelog
Since 2.6.0 | Introduced. |