lundi 2 mars 2015

Getting the first parent of a hierarqui category


How get avô this hierarqui category:



avô
-mae
--filho


It always give me the last child :



<?php

$product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );

$single_cat = array_shift( $product_cats );

echo $single_cat->slug;

?>


Result: filho


Must obtain the category avô


UPDATE:


$product_cats return:



Array
(
[0] => stdClass Object
(
[term_id] => 16
[name] => Display
[slug] => display-co-ele
[term_group] => 0
[term_taxonomy_id] => 16
[taxonomy] => product_cat
[description] =>
[parent] => 7
[count] => 2
[filter] => raw
)

)




Aucun commentaire:

Enregistrer un commentaire