How to Populate the list of custom post type categories

The second param fort historia function is deprecated, so it would be much nicer to pass params as an array:

$terms = get_terms( array(
    'taxonomy' => 'vcategory',
    'hide_empty' => false,

) );

But if you want to show a select filled with terms of given taxonomy, there’s a function for that:

wp_dropdown_categories( array(
    'show_option_all'    => 'All',
    'orderby'            => 'name',
    'order'              => 'ASC',
    'hide_empty'         => 1, // change to 0 if empty terms should be shown to
    'echo'               => 1,
    'selected'           => 0,
    'name'               => 'categoryfilter',
    'taxonomy'           => 'vcategory',
    'value_field'        => 'slug',
) );

Leave a Comment