I'm injecting Wordpress categories into my MySQL database. This is fine when it comes to categories without a parent. But when I add a child category it doesn't show in the Wordpress category list.
I believe this has something to do with Wordpress caching the query or the results for the category tree. I have tried to use this function to force Wordpress to clean the cache:
clean_term_cache( $ids, $taxonomy, $clean_taxonomy );
The problem I had was due to the fact that I was trying to recursively add categories and translate them. I had to add a category to the database with one translation and add the other translations afterwards. But whenever I ran the functions to clear the cache, WPML also went to work. This messed up the whole translation.
I ended up creating a category myself and immediately deleting it after running all of my code. This seemed to work.
It hurts my programmer heart to share this, but this is how I fixed my problem. So here goes:
$temp_term = wp_insert_term('Fake category', 'product_cat', ['description' => 'Temporary category', 'slug' => 'fake-cat-temp']); wp_delete_term($temp_term['term_id'], 'product_cat');