Hi I can display subcategory name in current product page (single product page) but it showed all the subcategory name. I just want to show subcategory name based on the product selected.

I have one category with two subcategories "black and blue". product A have black subcategory, product B have blue subcategory. when I go to product A, it show black and blue subcategory. All I want is when I go to product A, it only show black subcategory.

here my code

$args = array(
 'hierarchical' => 1,
 'show_option_none' => '',
 'hide_empty' => true,
 'parent' => 106,
 'taxonomy' => 'product_cat'
$subcats = get_categories($args);
echo '<p class=breadcrumb_single>Subject ';
foreach ($subcats as $sc) {
$link = get_term_link( $sc->slug, $sc->taxonomy );
  echo '<b><a href="'. $link .'">'.$sc->name.'</a></b>&nbsp;';
echo '</p>';
  • wp_get_post_terms is the function you are looking for. – Faham Shaikh Jun 19 at 17:46
  • Sorry I'm beginner, Can you please modify my code above? So I can more understand. – Wilda Sagita Jun 19 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.