How to get terms of custom taxonomy in WordPress ?
To get all terms of custom taxonomy in WordPress we can use get_terms() function. It retrieves the terms in a given taxonomy or list of taxonomies. Here is an example:
<?php
$terms = get_terms( array(
'post_type' => 'portfolio',
'taxonomy' => 'portfolio_category',
'hide_empty' => false,
) );
?>
<select class="form-control" name="portfolio_cat" id="parent_cat">
<option value="">Select Category</option>
<?php
foreach($terms as $term) {
?>
<option value="<?php echo $term->term_id; ?>">
<?php echo $term->name; ?>
</option>
<?php
}
?>
</select>