Skip to content

Instantly share code, notes, and snippets.

@croosen
Created December 9, 2015 13:18
Show Gist options
  • Save croosen/19b427ed97f6b564ccaa to your computer and use it in GitHub Desktop.
Save croosen/19b427ed97f6b564ccaa to your computer and use it in GitHub Desktop.
Groups WP taxonomies by parent
foreach( get_terms( 'product-categories', array( 'hide_empty' => false, 'parent' => 0 ) ) as $parent_term ) {
// display top level term name
echo $parent_term->name;
foreach( get_terms( 'product-categories', array( 'hide_empty' => false, 'parent' => $parent_term->term_id ) ) as $child_term ) {
// display name of all childs of the parent term
echo $child_term->name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment