• Dear all, I’m trying to show count in a dropdown menu level but I cannot get it work. Any help would be greatly appreciated. Here is the code I’m working on:

    function shandora_search_manufacturer_level2_field($value = array(), $class) {
    
    $o = apply_atomic('search_manufacturer_level2_field', '', $value, $class );
    
    if( $o != '' ) {
        return $o;
    }
    
    global $bon;
    $form = $bon->form();
    
    $loc_opt = array('any' => __('Any','bon'));
    
    if($value['manufacturer_level1'] != '') {
        $parent = get_term_by('slug', $value['manufacturer_level1'], 'manufacturer');
        if($parent) {
            $terms = get_terms('manufacturer', array('parent' => $parent->term_id, 'hide_empty' => true, 'show_count' => 1, 'show_lisiting_count' => true, ) );
            if($terms) {
                foreach($terms as $term) {
                    $loc_opt[$term->slug] = $term->name;
                    $show_listing_count = bon_get_option('show_listing_count', 'yes');
                    $term->name . '?(' . $term->count . ')';
                }
            }
        }
    }
    
    $o = $form->form_label(bon_get_option('manufacturer_level2_label'), 'manufacturer_level2');
    $o .= $form->form_dropdown('manufacturer_level2', $loc_opt, $value['manufacturer_level2'], 'class="'.$class.'"');
    if ( !empty( $terms ) && !is_wp_error( $terms ) ){
        echo '<ul>';
        foreach ( $terms as $term ) {
           echo '<li>' . $term->name . '?(' . $term->count . ')' . '</li>';
        }
        echo '</ul>';
    } 
    
    return apply_atomic( 'search_manufacturer_level2_field_output', $o );

    The counts are showing, they should be inside the dropdown not outside as shown in the following screenshot: https://switchpg.com/cars-menu.jpg

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘show count in dropdown menu’ is closed to new replies.