Tiago Rossi
Tiago Rossi

Reputation: 13

How to Create a Select Filter for Parent and Child Categories

I have this Wordpress category structure:

What I need are two selects that works like this: In the first one, only parent categories will appear, in this case the states only, e. g. State 1 and State 2.

When one state is selected the next/second select should list the children of the selected parent, in my above example the city names.

Example: When I select New York (state) the second select will show all New York cities. Then, I will press Search and it should go to http://mywebsite.com/state-selected/city/selected.

Upvotes: 0

Views: 1355

Answers (1)

Tiago Rossi
Tiago Rossi

Reputation: 13

It works for me now:

I used the plugin: http://appelsiini.net/projects/chained. You can see the example, it's perfect.

Then I used get_categories( $args ) twice, each one inside one select element.

The first one, only searching per parents and then putting them into options inside the loop.

The second only filtering by children and then putting all them inside options as well.

So, just used the Chained JQuery Plugin!

Upvotes: 0

Related Questions