wp_delete_post_revision()
Deletes a post revision by ID.
Order of operation:
- Checks for the existence of the revision using the function wp_get_post_revision. If the revision is not found, it will immediately return null.
- If the revision is found, its ID is passed to the function wp_delete_post for deletion.
- If the deletion is successful, the hook action wp_delete_post_revision is triggered.
- The result of the operation is returned.
Used By: wp_save_post_revision()
Hooks from the function
Returns
WP_Post|false|null.
WP_Poston successful deletion of the revision.nullon error (revision not found).falseon unsuccessful deletion attempt (database query failed).
Usage
wp_delete_post_revision( $revision_id );
- $revision_id(integer/WP_Post) (required)
- ID of the revision or its 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. |