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:
- 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);
- 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);
- Cập nhật trường
option_valuetrong bảngwp_optionsđể đặt category này làm mặc định:UPDATE wp_options SET option_value = '1' WHERE option_name = 'default_category';
Trao đổi về dự án của bạn!


