Just wanted to get an opinion, or ideas. I have an CPT called "Listings", and a custom taxonomy for it called directory-category
.
I have put together the below function to generate a list of links for the terms for the custom taxonomy.
I tried using get_term_link()
and couldn't get it to generate the links properly.
This code is working and when called it generates the links to the archive of each tax term.
However, I am thinking there is a better way to accomplish this, any insight would be appreciated, thanks!
function ebx_listing_tax_links() {
echo '<div class = "ebx-cat-bar">';
$url = site_url();
$cat = "/directory-category/";
$terms = get_terms( 'listing_categories' );
if($terms) : foreach ( $terms as $term ) {
?><a class="ebx-cat-link" href="<?php
echo $url;
echo $cat;
echo $term->slug;
?>"><?php echo $term->name; ?></a><?php
} endif;
echo '</div>';
}
get_term_link
isn't working correctly? What's wrong with it? How do you use it? How is the taxonomy registered?