Get the last level category - Wordpess

0

How can I do to get via query, only the last level of categories of this Woocommerce?

Example: Metals > Aluminum > Soda can

In my query below it takes the last two levels.

select distinct(tt.term_taxonomy_id) as categs from 
wp_term_relationships tr
left outer join wp_term_taxonomy tt on tt.term_id = tr.term_taxonomy_id
left outer join wp_terms on wp_terms.term_id = tr.term_taxonomy_id
where object_id in('" . $contatos_cod . "') and tt.taxonomy = 'product_cat' and parent > 0
    
asked by anonymous 10.08.2018 / 16:26

0 answers