I currently have a taxonomy called wpsc_product_category. Under that taxonomy I have several terms used as sub-categories, and finally each sub-category has a number of products. I'm trying to use wp_list_categories to show an ul starting from the parent category of the current product your are viewing. ¿Is this possible?


$taxonomy     = 'wpsc_product_category';
$orderby      = 'name'; 
$show_count   = 0;      // 1 for yes, 0 for no
$pad_counts   = 0;      // 1 for yes, 0 for no
$hierarchical = 1;      // 1 for yes, 0 for no
$title        = '';
$child_of     = $actualcategoryparentid

$args = array(
  'taxonomy'     => $taxonomy,
  'orderby'      => $orderby,
  'show_count'   => $show_count,
  'pad_counts'   => $pad_counts,
  'hierarchical' => $hierarchical,
  'title_li'     => $title
  'child_of'     => $child_of

<?php wp_list_categories( $args ); ?>

I thought of something like this, but I don't know how to retrieve $actualcategoryparentid.

Any ideas?



this will work:

$terms = wp_get_object_terms( $post->ID, 'wpsc_product_category' );
foreach($terms as $term){
    if($term->parent != 0){
        // this category has a parent and its id is $term->parent
  • So I just have to add that and then replace $terms for $actualcategoryparentid? – Rise Apr 26 '11 at 22:05
  • $term->parent within the foreach loop is what would be $actualcategoryparentid, but consider that if a product has more than one category with a parent, there will be more than one $term->parent – Milo Apr 26 '11 at 22:08
  • Oh i got it! I have to do $child_of = $term->parent; – Rise Apr 26 '11 at 22:09
  • Hmm I see. I hope I don't run into that problem too soon. Thanks for the helo Milo :) – Rise Apr 26 '11 at 22:10
  • Milo, would it be possible to get the name of $term->parent too? So I can echo it before listing the products? – Rise Apr 26 '11 at 22:51

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.