Posts from a subcategory chosen in a dropdown menu
-
Hey everybody,
I am looking for help to solve one issue I have spent a lot of time on.I need to have a dropdown menu showing the subcategories of a certain category (in my case, the parent category is called “Events”). When the user selects one item in the dropdown (so, one of my subcategories, let’s say “kids activities”) I need to see all the posts that belong to that certain subcategory.
This is the code that creates my dropdown:
<select name="type-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo attribute_escape(__('Type of Comedy')); ?></option> <?php $categories= get_categories('child_of=21'); foreach ($categories as $category) { $option = '<option value="/categories/Date/'.$category->category_nicename.'">'; $option .= $category->cat_name; $option .= ' ('.$category->category_count.')'; $option .= '</option>'; echo $option; } ?> </select>
This works just fine in showing my subcategories in the dropdown menu, but when I select one item nothing happens. I understand that I need to assign some right query in the <option value””> that retrieves the posts from the selected subcategory, but I just try try and without success. Would much appreciate if anybody could help.
Thank you
Chiara
- The topic ‘Posts from a subcategory chosen in a dropdown menu’ is closed to new replies.