0 %

Xóa toàn bộ Category của Wordrpess bằng MySQL

Xóa toàn bộ Category của Wordrpess bằng MySQL

Để xóa toàn bộ các category trong WordPress, bạn có thể sử dụng câu lệnh SQL sau:

DELETE FROM wp_terms
WHERE term_id IN (
SELECT term_id
FROM wp_term_taxonomy
WHERE taxonomy = 'category'
AND term_id != 1
);

DELETE FROM wp_term_taxonomy
WHERE taxonomy = 'category'
AND term_id != 1;

DELETE FROM wp_term_relationships
WHERE term_taxonomy_id IN (
SELECT term_taxonomy_id
FROM wp_term_taxonomy
WHERE taxonomy = 'category'
AND term_id != 1
);

Nếu bạn đã vô tình xóa luôn cả category Uncategorized mặc định, thì để khôi phục lại bạn có thể làm như sau:


  1. Tạo lại category mặc định bằng cách chèn bản ghi mới vào bảng wp_terms:

    INSERT INTO wp_terms(term_id, name, slug, term_group) 
    
    VALUES (1, 'Uncategorized', 'uncategorized', 0);







  1. Khai báo đây là một taxonomy (ngành) category trong bảng wp_term_taxonomy:

    INSERT INTO wp_term_taxonomy(term_taxonomy_id, term_id, taxonomy, description, parent, count)
    
    VALUES (1, 1, 'category', 'Uncategorized', 0, 0);







  1. Cập nhật trường option_value trong bảng wp_options để đặt category này làm mặc định:

    UPDATE wp_options 
    
    SET option_value = '1'
    
    WHERE option_name = 'default_category';









Việt Lâm Coder

Việt Lâm Coder

Senior Fullstack & System Architect

Cần hỗ trợ website? Gọi / Zalo 0944.71.4545.

Trao đổi về dự án của bạn!

VietLamCoder CMS — Nền Tảng Quản Trị Flat-File Siêu Tốc LamWeb.com.vn — Hệ Sinh Thái Thiết Kế Web & Kho Giao Diện 2026