Problem with wp_list_category with custom taxomy

I have a custom hierarchical taxonomy and I want to list in a dropdown menu all the top level “category” of the taxonomy that have post.

In my functions.php I’ve added this code:

function get_terms_dropdown_tm( $taxonomies, $args ) {
$args = array(
‘orderby’ => ‘name’,
‘show_count’ => 1,
‘order’ => ‘DESC’,
‘hide_empty’ => 1
);
$myterms = get_terms( $taxonomies, $argo );
$output = “<select name=’tassonomia_marca’>”;
$output .= “<option value=’#’>Seleziona la marca</option>”;

foreach($myterms as $term){
$root_url = get_bloginfo(‘url’);
$term_taxonomy = $term->taxonomy;
$term_slug = $term->slug;
$term_name = $term->name;
$link = $term_slug;
$output .= “<option value='” . $link . “‘>” . $term_name . “</option>”;
}

$output .= “</select>”;

return $output;
}

In the page, where I invoke this functions I’ve this code.

$taxonomies = array( ‘tassonomia_marca’ );
$select = get_terms_dropdown_tm( $args, $taxonomies );
$select = preg_replace( “#<select([^>]*)>#”, “<select$1 onchange=’return this.form.submit()’>”, $select );
echo $select;

The problem is that WP doesn’t take the $args and refill the dropdown menu with all the categories and without the post count

Read more here:: Problem with wp_list_category with custom taxomy

Leave a Reply

Your email address will not be published. Required fields are marked *