WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need a way to use get_terms and have it only grab the taxonomies of the current page. Example http://sitename.com/genre/hip_hop would only grab the taxonomies that also have the hip hop genre attached.

wp_get_object_terms almost works for me but wont loop the way get_terms does.

Here is what I have right now

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post();
$cam_brands = get_the_terms( $post->ID, 'sub_genre' );?>
<?php foreach( $cam_brands as $brand ) : ?>
<h3 class="genre-title"> <?php echo $brand->name; ?> </h3>

<?php $wpq = array( 'post_type' => 'track', 'taxonomy' => 'sub_genre', 'term' => $brand->slug, 'post_status' => 'publish','posts_per_page' => -1, 'caller_get_posts'=> 1 );
$brand_posts = new WP_Query ($wpq);?>
<?php foreach( $brand_posts->posts as $post ) : ?>
<li> <?php echo $post->post_title; ?> <a class="sc-player" href="<?php echo get('soundcloud_link'); ?>">track</a> </li>
<?php endforeach ?>
<?php endforeach ?>
<?php endwhile; ?>
<?php endif; ?>
share|improve this question

I think what you're looking for is get_the_terms, which you can specify a post ID and a taxonomy to retrieve the terms attached to it.

share|improve this answer

I think you might want to consider changing your outer foreach to a regular for statement. I have experienced issues with iteration counts while using a foreach inside a foreach (nested foreach statements). This might be affecting the output of your code. PHP has documented this on their website.

share|improve this answer

Your Answer


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.