<?php
function ds1_manage_custom_taxonomy_filter() {
    global $typenow;
    foreach(checkSettings("elements_filter_taxonomy") as $item){
        if( $typenow ==  sanitize_text_field($item["post_type"]) ){
            $taxonomy_names =  $item["taxonomy_names"];
            foreach ($taxonomy_names as $single_taxonomy) {
                $current_taxonomy   = isset( $_GET[$single_taxonomy] ) ? $_GET[$single_taxonomy] : '';
                $taxonomy_object    = get_taxonomy( $single_taxonomy );
                if(!$taxonomy_object){continue;}
                $taxonomy_name      = strtolower( $taxonomy_object->labels->name );
                $taxonomy_terms     = get_terms( $single_taxonomy );
                if(count($taxonomy_terms) > 0) {
                    echo "<select name='$single_taxonomy' id='$single_taxonomy' class='postform'>";
                    echo "<option value=''>All $taxonomy_name</option>";
                    foreach ($taxonomy_terms as $single_term) {
                        echo '<option value='. $single_term->slug, $current_taxonomy == $single_term->slug ? ' selected="selected"' : '','>' . $single_term->name .' (' . $single_term->count .')</option>'; 
                    }
                    echo "</select>";
                }
            }
        }
    }
}
 
add_action( 'restrict_manage_posts', 'ds1_manage_custom_taxonomy_filter' );
