loop through custom terms
-
I’m trying to get a list of terms for a custom loop.
I’ve tried some forms to get that, but can’t figure out what is going whrong.heres the thing:
there’s a custom post called photos, that has 2 taxonomies: photo_year and photo_tags.there are two pages, each one displaying photos from each year.
i can get the list of therms for the photo_tags taxonomy with this piece of code:
$terms = get_terms("photo_tags"); $count = count($terms); if ( $count > 0 ){ foreach ( $terms as $term ) { echo ' <li><a>slug .'" class="foto-filter-button '. $term->slug .'">'.$term->name.'</a></li> '; } }
but this returns a list of all terms, including those applied to the posts of the 2012 year.
so, I run out a loop:
<?php query_posts( array ( 'post_type' => 'photo', 'photo_year' => '2011', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => -1) );
and then a code for getting the terms for these posts:
$terms = wp_get_post_terms($post->ID,'photo_tags'); foreach($terms as $term){ echo ' <li><a>slug .'" class="foto-filter-button '. $term->slug .'">'.$term->name.'</a></li> '; }
this code get the terms, but it gets all of them, repeating a lot (because there are single tags applied to multiple posts).
so, I would like to know how to get the single terms, without repeating each entry every time it apears in a post in the loop.I think that it must be something looking for repeated id’s of the terms or something like that.
ps.: sorry for the bad english.
- The topic ‘loop through custom terms’ is closed to new replies.