I am in the midst of constructing a importer that makes use of WC API to import merchandise, i’ve run into a problem the place i want so as to add customized taxonomy tree to the product by ids however i am unable to determine how you can accomplish that with out working costly loops.
I’ve a listing of taxonomy tree names eg. Father or mother->Baby->Grandchild, i want to exchange these names with the corresponding ID eg. 12312->324234->2343243 in order that the wordpress is aware of which taxonomy phrases are associated to the product.
The issue is each product has 100+ attainable time period combos and within the database we’ve over 80k phrases to match it with. There are additionally many phrases which are named the identical.
So for each mixture i must loop by these 80k phrases to determine how the tree appears like and what id corresponds to the time period identify.
Is not there a greater resolution i might use? One thing that will flip this hierarchy tree
“Father or mother time period -> Baby time period -> Grandchild time period”
Into
“{parent_term_id} -> {child_term_id} -> {grandchild_term_id}
An SQL question perhaps? I am undecided about how it could seem like although.
That is what i am working with proper now
add_action('init', perform(){
$mother or father = get_term_by('identify', 'BENELLI', 'fitment');
$kids = get_terms(['taxonomy' => 'fitment','parent' => $parent->term_id]);
$baby = present(array_filter($kids,
perform($merchandise){
return trim($item->identify) == 'TRK 502 ABS' ? true : false;
}
));
$grandChildren = get_terms(['taxonomy' => 'fitment','parent' => $child->term_id]);
$grandChild = array_filter($grandChildren,
perform($merchandise){
return trim($item->identify) == '2017' ? true : false;
}
);
var_dump([
'parent' => $parent,
'child' => $child,
'grandchild' => $grandChild
]);
die();
}, 10);