I have created a plugin that add geographic data to Wordpress. According to this answer the taxonomy data should not be stored in the database, however it seems to be stored:
mysql> select * from wp_term_taxonomy where taxonomy='geoareas' limit 10;
+------------------+---------+----------+-------------+--------+-------+
| term_taxonomy_id | term_id | taxonomy | description | parent | count |
+------------------+---------+----------+-------------+--------+-------+
| 953 | 699 | geoareas | | 0 | 2 |
| 954 | 700 | geoareas | | 699 | 0 |
| 955 | 701 | geoareas | | 700 | 0 |
| 956 | 702 | geoareas | | 700 | 0 |
| 957 | 703 | geoareas | | 700 | 0 |
| 958 | 704 | geoareas | | 700 | 0 |
| 959 | 705 | geoareas | | 700 | 0 |
| 960 | 706 | geoareas | | 700 | 0 |
| 961 | 707 | geoareas | | 700 | 0 |
| 962 | 708 | geoareas | | 700 | 0 |
+------------------+---------+----------+-------------+--------+-------+
10 rows in set (0.00 sec)
Why is that data stored in the database? And what would be the proper way to remove the data on register_deactivation_hook
since wp_delete_term()
seems to only remove the terms and not the entire taxonomy from the database. Do I manually need to remove all Term-Post and Term-CustomPostType associations in the database, and then all references to the taxonomy itself? Or is there an internal WP function that I should be using? The obvious wp_delete_taxonomy()
does not exist!
EDIT: It seems to me that all the taxonomy data storded in the database is stored in the wp_term_taxonomy
, wp_terms
, and wp_term_relationships
tables. Would these three queries be sufficient to purge the taxonomy data from the database on register_deactivation_hook()
?
DELETE tr FROM wp_term_taxonomy tt INNER JOIN wp_term_relationships tr ON tt.term_taxonomy_id=tr.term_taxonomy_id WHERE taxonomy='geoareas';
DELETE tt FROM wp_term_taxonomy tt INNER JOIN wp_terms t ON tt.term_id=t.term_id WHERE taxonomy='geoareas';
DELETE FROM wp_term_taxonomy WHERE taxonomy='geoareas';