How to display custom taxonomy values in WordPress

I’m working on an e-commerce website where I need to show company names for each product. I created a custom taxonomy called ‘company’ to store this information, but I’m having trouble displaying it on the frontend.

Right now I can successfully show regular WordPress tags using this code:

<div class="vendor-info">Company: <?php echo $item->get_tags(); ?></div>

This works perfectly for tags, but when I try to get my custom taxonomy instead, nothing shows up. I attempted using this approach:

<?php echo $custom_tax->title ?>

But it doesn’t work at all. Each product should display something like ‘Company: Apple’ or ‘Company: Samsung’ depending on which taxonomy term is assigned to that specific product. What’s the correct way to retrieve and display custom taxonomy terms in WordPress?

Use wp_get_post_terms() for custom taxonomies. $custom_tax->title won’t work because you haven’t retrieved the taxonomy data first. Here’s what worked for me:

$company_terms = wp_get_post_terms(get_the_ID(), 'company');
if (!empty($company_terms)) {
    echo 'Company: ' . $company_terms[0]->name;
}

I find this more reliable than get_the_terms(), especially with custom post types. Double-check your taxonomy slug matches exactly what you registered it as. I once spent hours debugging because my taxonomy was registered as ‘companies’ but I was querying ‘company’.

Had this exact problem building a product catalog last year. You’re trying to access taxonomy data without fetching it from the database first. Both answers above work, but I prefer get_the_term_list() when you need formatted output - it handles empty checks and linking automatically. Try echo get_the_term_list(get_the_ID(), 'company', 'Company: ', ', ', ''); for clean output without manual array handling. The fourth parameter separates multiple terms, fifth shows what comes after the list. Also check that your taxonomy has public and show_ui set to true in registration - frontend retrieval gets wonky otherwise.

try get_the_terms() instead. something like $terms = get_the_terms($post->ID, 'company'); echo $terms[0]->name; should work for your custom taxonomy. just check if terms exist first or you’ll get errors.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.