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 am returning a list of the terms from three different taxonomies.

$terms = get_terms(array("air-categories","web-categories","ink-categories"));

I get the list and I need each to link to a different section of my site based on what taxonomy they are in but I can't seem to think of a way to return an if statement for which taxonomy each term is in.

global $post;
$published_posts = wp_count_posts()->publish;
$terms = get_terms(array("air-categories","web-categories","ink-categories"));
    $count = count($terms);
    if ( $count > 0 ){
        echo "<ul>";
        foreach ( $terms as $term )             {
            $c = $term->count;
            $term_percent = log($c)*5;
                                                    echo "<li><a href='";
        if( ***would like to check for the taxonomy here*** ) {
              echo "***and then change the link here based on the result***";
         }
        echo "'><span class='label'>" . $term->name . "</span><span class='bar' style='width:".$term_percent."%;'></span><span class='count'>". $term->count ."</span></a></li>";
        }
        echo "</ul>";
                                                 }
    wp_reset_query();
share|improve this question
add comment

1 Answer 1

$term->taxonomy is the taxonomy name for each term, $term->term_taxonomy_id the – wait for it! – taxonomy ID.

To get the display names use get_taxonomy():

$terms = get_terms( array( 'category', 'post_tag' ) );

foreach ( $terms as $term )
{
    $tax_name = esc_html( get_taxonomy( $term->taxonomy )->labels->name );
    echo "$term->name ($tax_name)<br>";
}
share|improve this answer
    
thank you very much. i think part of my problem for most of the time is that i wasnt working inside that foreach loop when trying to get the taxonomy name. –  Jonathan Apr 17 '13 at 17:52
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.