I decided to create child categories in my website to organize my structure. I made it manually via database manipulations by:
1- insert child categories into gsv_terms
2- Link them with parent categories in gsv_term_taxonomy
(I had a list of parent categories IDs to link children with them).
I can see that in my Location categories (custom taxonomy) that the children are linked to the parent category.
However, I can't get the parent tax to identify its children taxonomies, which has also broken my filters as visiting parent category does not show anything at all.
This returns empty array:
$parent_location = 165;
$term = get_term($parent_cat, 'job_listing_location');
$term_children = get_term_children($term->term_id, 'job_listing_location');
print_r($term_children); // Empty Array ()
But doing it manually via $wpdb
works:
global $wpdb;
$children = $wpdb->get_results($wpdb->prepare("
SELECT term_id FROM $wpdb->term_taxonomy WHERE parent = %d
AND taxonomy = 'job_listing_location'", $term->term_id));
$children_ = wp_list_pluck($children, 'term_id');
print_r($children); // returns all child taxonomies
What did I do wrong here?
4 hours on this, and it was because I didn’t flush the cache.
This is all what was missing:
`delete_option(“job_listing_location_children”);`
`wp_cache_delete(‘all_ids’, ‘job_listing_location’);`
`wp_cache_delete(‘get’, ‘terms’);`
Ight everyone, I’m off enjoying my stroke.