0

In order to remove thousands of old taxonomies and terms used during development, I recommended the following SQL queries to another dev:

TRUNCATE wp_terms;
TRUNCATE wp_termmeta;
TRUNCATE wp_term_taxonomy;
TRUNCATE wp_term_relationships;

The dev told me that after he ran these queries he had a myriad of problem and other data being deleted. Other than terms and taxonomies, what other data might be stored in those tables? We know that non-post related information is stored in wp_posts, such as Navigation Menus. In a similar vein, are non-terms data stored in the above-mentioned tables?

EDIT: Note that one can read the table structures to see exactly what obvious data is being stored, which all seems related to the Terms, Taxonomies, and their metadata and relations. This question is asking what non-obvious data may be stored in those tables as well, i.e. if they were to be truncated what data not related to Terms or Taxonomies would be lost. This is in a similar vein to loosing Navigation Menu configurations when truncating wp_posts, which is not obvious from examining the table structure and names of wp_posts and related tables.

1 Answer 1

1

There are a lot of data stored in those 4 tables

  • wp_terms stores the term_id, name, slug and term_group ID for a specific term.

  • wp_termmeta stores any meta data which you add to a term. This is a new feature introduced in WordPress 4.4

  • wp_term_taxonomy holds the other info of a term stored in wp_terms. This tables stores the relationship between the term ID and other relative info such as term_taxonomy_id, taxonomy, description, parent and term count

  • wp_term_relationships stores the relationship between posts and their terms. This table just stores the object_id (which is the post ID) and the term_taxonomy_id (which is the term ID) and term_order. Deleting this table will result in posts loosing their term relationships, ie, there will be no more terms associated to posts

It should be relative safe to delete the wp_termmeta table. This should only break functions which relies on this term meta data at worst. Deleting ANY of the other three tables will break terms and any relationships they might have to posts. It is really not a clever idea to delete tables blindingly.

EDIT

This question is asking what non-obvious data may be stored in those tables as well

Apart from wp_termmeta and apart from storing term data and the post ID's to which those terms are connected to, there should not be any non-relevant, non-obvious data stored in these tables by default. Some plugins might introduce some extra columns to store additional data related to terms, but this is as far as it should go. WorPress itself does not store any additional data from anywhere in these tables

What is obvious though, if you delete these tables, any function/class/code which relies on this data will be broken

2
  • Thank you Pieter. Actually, all that you mention is obvious from looking at the table structure. I've +1 the post because it is informative, but I did mean to ask what are the non-obvious things, in a view similar to the Navigation Menus being stored in wp_posts. I'll clarify the question.
    – dotancohen
    Commented Apr 3, 2016 at 10:46
  • See my edit, hope this answers your question Commented Apr 3, 2016 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.