0

I have portfolio on my site and i want add dropdown switching subcategories for taxanomy 'potfolio-types'

For example:

Category A

  • subcategory 1
  • subcategory 2
  • etc...

when're in category A, the drop-down list shows the child category. When selecting child category, go to her.

I use this code

<?php 
$args = array('hide_empty'=>1,'depth'=>1,'hierarchical'=> 0, 'show_count'=> 1,'taxonomy'=> 'portfolio-types',);
?>
<ul>
<?php wp_dropdown_categories( $args ); ?>
</ul>

But the list shows all the categories and subcategories. And there is no transition.

2
  • Have you looked into the 'child_of' argument?
    – coopersita
    Aug 3, 2015 at 16:44
  • Sorry, but I dont understand how to use it.
    – Tapioka
    Aug 5, 2015 at 13:22

1 Answer 1

0

The 'child_of' argument lets you select subcategories from a parent category, and a you can get the current taxonomy id to pass as the value:

<?php 

$category_id = get_queried_object_id();
$args = array(
    'hide_empty'=>1,
    'depth'=>1,
    'hierarchical'=> 0, 
    'show_count'=> 1,
    'taxonomy'=> 'portfolio-types', 
    'child_of' => $category_id
    );
?>
<ul>
<?php wp_dropdown_categories( $args ); ?>
</ul>

So in the example above, only children (sub-categories) of portfolio-type of the current category ID will be displayed.

Note that this code will only work if you are in a taxonomy archive page, which I think that's what you intend to do.

2
  • Yes, it`s work. Now I understand. Thank you very much.
    – Tapioka
    Aug 6, 2015 at 6:13
  • Good to hear. I see that you are new to SO; to mark the question as answered, click the check mark on the left (below the 0 and arrows) of my answer.
    – coopersita
    Aug 6, 2015 at 14:13

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.