Guide to Delete TranslatePress Translation for a Specific Post (Reset Translation)

Issue: Translation is faulty or not updated

During the operation of a multilingual website with TranslatePress, sometimes you will encounter cases where the translation is faulty (for example: Chinese is displayed as Vietnamese) or you want to reset the entire translation of a specific post so that the AI translates it again from scratch.

This post will guide you through 2 ways to completely delete the translation of any post (Post, Page, Product…) without affecting other posts.

Method 1: Delete using SQL (Most Accurate)

This is the safest and most accurate method, helping you thoroughly delete data in the database.

Step 1: Find the Post ID

Access the WordPress admin page, go to the section Posts 5px Pages. Hover the mouse over the title of the post you want to process, look down at the browser's status bar, you will see the number ID (e.g.: post=123).

Step 2: Determine the post code and language table

  • Post ID: For example, it is 123
  • Language code to delete: For example, Chinese (China) is usually zh_cn, English is en_us. The table name in the database will be in the form wp_trp_dictionary_vi_zh_cn (if translating from Vietnamese to Chinese).

Step 3: Run the SQL command

Open phpMyAdmin (or similar database management tool), find the website's database and run the following command:


-- Replace '123' with your post ID
-- Replace 'wp_trp_dictionary_vi_zh_cn' with the language table name you want to delete
DELETE FROM `wp_trp_dictionary_vi_zh_cn` 
WHERE `original_id` IN (
    SELECT `original_id` 
    FROM `wp_trp_original_meta` 
    WHERE `meta_key` = 'post_parent_id' 
    AND `meta_value` = '123'
);

After running, the entire translation of that post will be deleted. You just need to go to the homepage and reload the page, the system will automatically translate it anew.


Method 2: Use PHP Code (Quick and Simple)

Nếu bạn không rành về database hoặc không muốn đụng vào phpMyAdmin, bạn có thể dùng đoạn code nhỏ sau đây.

Step 1: Add code to functions.php

Open file functions.php of the active theme (Appearance -> Theme Editor), and add this code to the end of the file:


add_action('init', function() {
    // Thay đổi số 123 thành ID bài viết bạn muốn xóa
    $post_id_to_clean = 123; 
    
    // Thay đổi thành mã ngôn ngữ bạn muốn xóa (ví dụ: vi_zh_cn, vi_en_us)
    $lang_pair = 'vi_zh_cn'; 
    
    if (isset($_GET['clean_post_id']) && $_GET['clean_post_id'] == $post_id_to_clean) {
        global $wpdb;
        $meta_table = $wpdb->prefix . 'trp_original_meta';
        $dict_table = $wpdb->prefix . 'trp_dictionary_' . $lang_pair;
        
        // Kiểm tra xem bảng có tồn tại không
        if ($wpdb->get_var("SHOW TABLES LIKE '$dict_table'") != $dict_table) {
            wp_die("Bảng $dict_table không tồn tại. Hãy kiểm tra lại mã ngôn ngữ.");
        }

        // Lấy danh sách ID chuỗi thuộc về bài viết này
        $original_ids = $wpdb->get_col($wpdb->prepare(
            "SELECT original_id FROM $meta_table WHERE meta_key = 'post_parent_id' AND meta_value = %s",
            $post_id_to_clean
        ));
        
        if (!empty($original_ids)) {
            $ids_placeholder = implode(',', array_fill(0, count($original_ids), '%d'));
            $wpdb->query($wpdb->prepare(
                "DELETE FROM $dict_table WHERE original_id IN ($ids_placeholder)",
                $original_ids
            ));
            echo "Đã xóa sạch bản dịch cho bài viết ID: " . $post_id_to_clean;
        } else {
            echo "Không tìm thấy chuỗi nào cần xóa hoặc bài viết chưa được dịch.";
        }
        exit;
    }
});

Step 2: Run the delete command

After saving the file, access the following URL in your browser (log in as admin first):

https://website-cua-ban.com/?clean_post_id=123

(Remember to replace 123 with the post ID you entered in the code).

Step 3: Delete the code

After seeing the message “Successfully deleted translation…”, go back to the file functions.php and delete the code snippet just added for security and to keep the website lightweight.


Conclusion

Above are 2 methods to help you reset the translation for a specific post in TranslatePress. This is very useful when you change the original content too much or when the automatic translation is faulty.

Wish you success!

DPS.MEDIA