0

Finally i cant get subcategories from a custom post type category and everything works fine. The problem is when i want get the same but with a dropdown for responsive. Is possible? i need hide empty terms too. thanks!

here the code:

<ul>
<?php $tax = get_term_by('slug', 'cursos', 'portfolio_category');
$tax_id = $tax->term_id;
$args = array(
'child_of'   => $tax_id,
'taxonomy' => 'portfolio_category',
'orderby' => 'name',
'show_count' => 0,
'pad_counts' => 0,
'hierarchical' => 0,     
'title_li' => '',
'hide_title_if_empty' => 0
);
wp_list_categories($args); ?></ul>
0

Wordpress always has similar function to a list, you may try wp_dropdown_categories instead of wp_list_categories. It takes almost the same arguments, which is not related to list items.

$tax = get_term_by('slug', 'cursos', 'portfolio_category');
$tax_id = $tax->term_id;

$args = array(
    'child_of'   => $tax_id,
    'taxonomy' => 'portfolio_category',
    'orderby' => 'name',
    'show_count' => 0,
    'hierarchical' => 0
);

wp_dropdown_categories($args);

This function echoes complete select element by default, so you don't need manually echo select tags.
Check documentation for additional attributes if you need them (displaying option if there is no term or for selecting all terms)
Code Reference: wp_dropdown_categories

Your Answer

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

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