0

i have a custom post type called "item" and it has taxonamies called "item_location", "item_category"

now i am trying make two dropdowns in home page.

first drop down has data of "item_location" second drop down has data of "item_category"

by default on page load first dropdown get all locations and second dropdown will be in disable mode.

once visitor selects some value from the first dropdown then second dropdown has to be enabled by ajax and it should contain the data of categories under the selected(posted value of item_location) location.


theme name was Javo directory

updating code


 $parent
        , 'hide_empty'      => false
    );
    $javo_this_terms        = (Array)get_terms($taxonomy, $javo_this_args);
    $javo_this_return       = '';
    $javo_this_attribute    = '';
    if( count( $javo_this_terms )  $value){
            $javo_this_attribute .= $attr . '="'. $value .'" ';
        }
    };
    $depth++;
    foreach( $javo_this_terms as $term ){
        switch( $el ){
        case 'select':
            $javo_this_return   .= sprintf('%s%s%s'
                , $term->term_id
                , ( in_Array( $term->term_id, (Array)$default) ? ' selected':'' )
                , str_repeat( $separator, $depth-1 ).' '
                , $term->name
                , javo_get_selbox_child_term_lists_callback($taxonomy, $attribute, $el, $default, $term->term_id, $depth, $separator)
            );
        break;
        case 'ul':
        default:
            $javo_this_return   .= sprintf('%s %s%s'
                , $javo_this_attribute
                , $term->term_id
                , $term->name
                , str_repeat( '-', $depth-1 )
                , $term->name
                , javo_get_selbox_child_term_lists_callback($taxonomy, $attribute, $el, $default, $term->term_id, $depth, $separator)
            );
        }; // End Switch
    };

    return $javo_this_return;
};
add_filter('javo_get_selbox_child_term_lists', 'javo_get_selbox_child_term_lists_callback', 10, 7);

/**
* Element Get children terms
**/
function javo_get_el_child_term_lists_callback($taxonomy, $default=null, $parent=0, $depth=0){
    global $wp_query
    , $javo_tso
    , $javo_theme_option;
    $javo_this_args         = Array(
        'parent'            => $parent
        , 'hide_empty'      => false
    );
    $javo_current_terms     = Array();
    if( !empty( $wp_query->queried_object ) ){
        $javo_current_term      = $wp_query->queried_object;
        if( !empty( $javo_current_term->term_id ) && !empty( $javo_current_term->taxonomy ) )
        {
            $javo_current_terms     = (Array)javo_get_archive_current_position($javo_current_term->term_id, $javo_current_term->taxonomy);
        }
    };
    $javo_this_terms        = (Array)get_terms($taxonomy, $javo_this_args);
    $javo_this_return       = '';
    $javo_this_attribute    = '';
    if( count( $javo_this_terms )  $value){
            $javo_this_attribute .= $attr . '="'. $value .'" ';
        }
    };
    $javo_this_return_before = sprintf(''
        , ( in_array($parent, $javo_current_terms) ? 'is_current':'')
    );

    $depth++;
    foreach( $javo_this_terms as $term ){
        $javo_this_return   .= sprintf('%s %s'
            , ( $depth == 1 ? 'javo-is-top-depth':'' )
            , ( in_array($term->term_id, $javo_current_terms) ? ' current' : '')
            , get_term_link($term)
            , ''
            , $term->name
            , javo_get_el_child_term_lists_callback($taxonomy, $default, $term->term_id, $depth)
        );
    };
    if( $depth > 1 ){
        $javo_this_return = $javo_this_return_before.$javo_this_return.'';
    };

    return $javo_this_return;
};
add_filter('javo_get_el_child_term_lists', 'javo_get_el_child_term_lists_callback', 10, 5);

?>


 location ) ) : ?>
                        
                            
                                
                                get('location', 0)
                                    , 0
                                    , 0
                                    , 1
                                ); ?>
                            
                        
                    

                    category ) ) : ?>
                        
                            
                                
                                get('category', 0)
                                    , 0
                                    , 0
                                ); ?>
                            
                        
                    

                    
  • 1
    show us what you have tried. – Milo Jun 16 '15 at 15:01
  • updated the thread with my current code @Milo – sunil Jun 17 '15 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.