WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to get a chained select to work to select a state then a city with that state. (2 fields).

Here is what I've got:

First my function to create the menu using get_categories().

First problem: Not sure what to put for $child to get it to only show child categories.

function taxonomy_dropdown($dropID, $exclude, $taxonomy, $parent, $child) {
    $args = array(
        'type'                     => 'post',
        'child_of'                 => $child,
        'parent'                   => $parent, 
        'orderby'                  => 'name',
        'order'                    => 'ASC',
        'hide_empty'               => 0,
        'hierarchical'             => 1,
        'exclude'                  => $exclude,
        'include'                  => '',
        'number'                   => '',
        'taxonomy'                 => $taxonomy,
        'pad_counts'               => false

    $categories = get_categories( $args );

    $menu = '<select name="'.$dropID.'" id="'.$dropID.'" class="postform">';

    foreach($categories as $category) {
        $menu .= '<option class="" value="'.$category->name.'">'.$category->name.'</option>';
    $menu .= '</select>';
    echo $menu;

In my plugin, the function is called like so:


The second one for 'city' doesn't work because of the above problem of I can't get it to only get the child categories.

So once I get that to work, I should have 2 selects, one showing 'states' and one showing 'cities.'

Now here is where I get lost. I want to use chained.js (http://www.appelsiini.net/projects/chained) to turn these two select menus into a chained select.

I'm pretty sure I've enqueued it into my plugin properly:

function includeChained() {
        plugins_url( '/js/chained/chained.min.js' , __FILE__ ),
        array( 'jquery' )
add_action( 'wp_enqueue_scripts', 'includeChained' );

Now I'm totally clueless about how to use jQuery and JavaScript beyond the ultra basics. I tried what the docs show for using the class based usage:


But nothing happens.

share|improve this question
Can you get it working in principle on proof of concept, sans WordPress? Live page, demonstrating the issue would probably be helpful as well. – Rarst Nov 22 '13 at 10:29
Ok, Ive got it working now: weedstarter.com/add-location -- Ive got 2 drop downs, one showing parent categories only and one showing child categories only. From what Ive figured out about how to use chained.js, all I need to do to get it to work is to get the class of the child category options to be the name of the parent category and it should work. – Jon Furry Nov 22 '13 at 20:48
@JonFurry Please add that as separate answer. You can mark it as solution just two days after that. We'd appreciate that. – kaiser Feb 11 '14 at 0:48

Code is here: Wordpress chained categories

I write the same code for categories. You can edit for your needs. I used the that js plugin: http://www.appelsiini.net/projects/chained

share|improve this answer
Please explain why this answer is helpful. Answers should be more than plain links. They should actually be an answer instead of a route where someone will maybe find an answer. Please help preventing link rot, edit your answer and provide the needed information that helps the OP as well as later visitors to solve their problem. – kaiser Apr 10 '14 at 17:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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