Created
January 29, 2018 23:27
-
-
Save alimoshen/a716e5d2c369c49e67d89e5808b746ae to your computer and use it in GitHub Desktop.
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
function get_taxonomy_parents($id, $taxonomy, $link = false, $separator = '/', $nicename = false, $visited = array()) { | |
$chain = ''; | |
$parent = &get_term($id, $taxonomy); | |
if (is_wp_error($parent)) { | |
return $parent; | |
} | |
if ($nicename) | |
$name = $parent -> slug; | |
else | |
$name = $parent -> name; | |
if ($parent -> parent && ($parent -> parent != $parent -> term_id) && !in_array($parent -> parent, $visited)) { | |
$visited[] = $parent -> parent; | |
$chain .= get_taxonomy_parents($parent -> parent, $taxonomy, $link, $separator, $nicename, $visited); | |
} | |
if ($link) { | |
// nothing, can't get this working :( | |
} else | |
$chain .= $name . $separator; | |
return $chain; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment