Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top