Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Multiple Category Dropdown WordPress

I have a support page on our site that provides customers the ability to view product documents and software from a specific category. You can see it here [[LINK href="http://www.openeye.net/support/software-updates/"]]http://www.openeye.net/support/software-updates/[[/LINK]] The drop-down allows you to choose which product you would like view resources from.

I've been searching for a way to allow the user to choose the category first.
<blockquote>Cameras</blockquote>
Then choose the product. Hopefully, without reloading the page.
<blockquote>CM-135</blockquote>
I've posted information on wordpress.stackexchange but haven't received any conclusive answers. [[LINK href="null"]]http://wordpress.stackexchange.com/questions/10570/multiple-level-category-drop-down[[/LINK]]

Here is the current code for the category dropdown.
<form action="<?php bloginfo('url'); ?>/" method="get">
<?php
$select = wp_dropdown_categories('orderby=name&echo=0&depth=0&hierarchical=1&exclude=5,4');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
echo $select;
?>
<noscript>
<input type="submit" value="View" />
</noscript>
</form>


Any help would be appreciated.

Answers (3)

2011-08-06

Hai Bui answers:

Can you post the code for the current dropdown?


Hai Bui comments:

It's pretty hard. This tutorial explains how to do it: http://www.wpsharing.net/2011/02/implement-ajax-in-wordpress-themes/
It's exactly what you want

2011-08-06

Reland Pigte answers:

I can work on this if you like :)


Zach Shallbetter comments:

How do you mean?


Reland Pigte comments:

The same concept as this http://wpquestions.com/question/show/id/2797 I also wrote a plugin that suits the functionality.

But I think Jurre Hanema got it right ;)

Cheers

2011-08-06

Jurre Hanema answers:

I created a small plugin that should do what you want. It lets you select a category and then pulls the child categories from the server using an AJAX request, displaying them in a second drop down.

You can download it here: www.stack.nl/~jurre/mcd_plugin.zip

In your theme, at the location where you want the two dropdowns to appear, simply insert the following code:


<?php
if(function_exists('mcd_print_dropdowns')) mcd_print_dropdowns();
?>


Please let me know if it works for you!


Zach Shallbetter comments:

Excellent, it partially works, when you select the item from the second category drop-down it doesn't take you to the category page. It also show's an empty short drop-down before you select the first one.

Could I also get it to say select-one as a default and only show one initially?

Awesome job!