Skip to content

Instantly share code, notes, and snippets.

@hirejordansmith
Created September 3, 2015 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirejordansmith/fa85cb1af2698603679a to your computer and use it in GitHub Desktop.
Save hirejordansmith/fa85cb1af2698603679a to your computer and use it in GitHub Desktop.
How to display only children of the current term
<?php
// How to only get children of the current term
?>
<div class="category-list">
<?php
$term_id = get_queried_object()->term_id;
$term = get_term($term_id, 'product_cat' );
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
'child_of' => $term->term_id,
'parent' => $term->term_id
);
$sub_terms = get_terms( 'product_cat', $args);
//print_rr($subproducts);
foreach ($sub_terms as $term) { ?>
<li> <a href="<?php echo get_term_link( $term ); ?>"><?php echo $term->name; ?><?php /*echo "<span class='count'>" . $subproduct->count . "</span>"; */ ?></a></li>
<?php } ?>
</div>
@cgdmohamed
Copy link

Thank you for this snippet, really made my day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment