How to delete post revisions only for a specific post identified by its ID using an SQL query?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
If you need an SQL query, then this option should be suitable
function src_flush_revisions () {
global $wpdb;
$post_id = 5//exp post id
if ( isset( $timeLimit ) ) {
$revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT `ID` FROM $wpdb->posts WHERE `post_type` = 'revision' AND `post_parent` = %d", $post_id ) );
foreach ( $revision_ids as $revision_id ) {
wp_delete_post_revision( $revision_id );
}
}
}
add_action( 'admin_init', 'src_flush_revisions' );
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0