How to delete post revisions only for a specific post identified by its ID using an SQL query?

1 Answer 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' );

  • So the query to execute if you want to do this only once is DELETE FROM wp_posts WHERE `post_type` = 'revision' AND `post_parent` = (post id). Thanks! Dec 30, 2020 at 12:54
  • 1
    @programings You should use the PHP code. Just using that SQL will leave meta and term information behind. Dec 30, 2020 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.