• Resolved David Gard

    (@duck_boy)


    Hey all,

    I have created a custom taxonomy, Contacts, and would like to display a list of them, along with some other code, next to a single post. Trouble is if there is no Contacts related to the post the additional code is still shown.

    Is there a way of checking to see if a post has Contacts related to it? I suspect it is pretty much the same as checking for Tags, but I don’t know how to do that either!

    Thanks for the help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • What code are you currently using? …

    Something along these lines should be sufficient, but i have no idea what you’re doing with the terms.. so couldn’t give a sutiable loop example for the terms..

    <?php
    $terms = get_the_terms( $post->ID , 'taxonomy-name' );
    if( $terms ) {
    // Loop over terms code would go here
    }
    else {
    // No terms for the post
    }
    ?>

    Thread Starter David Gard

    (@duck_boy)

    Thanks t31os_

    I am now able to get the below output using print_r, but one silly question – how do I output that data? For example, this isn’t working –

    foreach($contacts as $contact){
        echo '<li><a>' . $contact->name . '</a></li>';
    }

    Thanks.

    Array ( [96] => stdClass Object ( [term_id] => 96 [name] => Amanda Inch [slug] => amanda-inch [term_group] => 0 [term_taxonomy_id] => 110 [taxonomy] => contacts [description] => [parent] => 0 [count] => 1 [object_id] => 1878 ) [95] => stdClass Object ( [term_id] => 95 [name] => Richard Pinney [slug] => richard-pinney [term_group] => 0 [term_taxonomy_id] => 109 [taxonomy] => contacts [description] => [parent] => 0 [count] => 1 [object_id] => 1878 )

    Thread Starter David Gard

    (@duck_boy)

    Don’t worry, sussed that – I was doing something to $contacts that was mucking it up.

    Thanks for the help.

    Happy to help.. ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Count individual post tags.’ is closed to new replies.