Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to return all the terms for a particular taxonomy (so eventually I can create a link for it). At the moment, this function I've written only returns terms for the current post. How can I just return a list of all of them?

<h2>Get terms</h2>
<?php
    $taxonomies=get_taxonomies('','object'); 
    foreach($taxonomies as $tax){
        echo "<h2>$tax->name</h2>";
        $terms = get_terms($tax->name);
        foreach($terms as $term){
            print_a($term->name);
        }
    }
?> 

Just for a bit more detail, the site is about wine, and one taxonomy is grape type. If the current wine is a Chardonnay, it returns "Chardonnay", but I'd like it to return "Chardonnay, Merlot, Pinot Grigio" etc.

The print_a function is just a print_r wrapped in pre tags.

Thanks

share|improve this question
add comment

1 Answer

Ah, my fault I got it, the all important hide_empty=0

Get terms

<?php
    $taxonomies=get_taxonomies('','object'); 
    foreach($taxonomies as $tax){
        echo "<h2>$tax->name</h2>";
        $terms = get_terms( $tax->name, 'orderby=count&hide_empty=0' );
        foreach($terms as $term){
            print_a($term->name);
        }
    }
?> 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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