Created
February 17, 2016 23:09
-
-
Save eliasdorigoni/29d783c577fc8306c5d5 to your computer and use it in GitHub Desktop.
Ejemplo de recursividad en taxonomias de WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Arma recursivamente un arbol con las taxonomias jerárquicas. | |
* Devuelve un array. | |
* @param object $terms retorno de get_terms | |
* @return array | |
*/ | |
function armarArbol($terms, $padre = 0, $profundidad = 0) { | |
if($profundidad >= 8) return ''; | |
$retorno = array(); | |
foreach ($terms as $i => $term) { | |
if ($term->parent == $padre) { | |
$retorno[$i] = (array) $term; | |
$retorno[$i]['children'] = armarArbol($terms, $term->term_id, $profundidad + 1); | |
} | |
} | |
return $retorno; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment