Site icon Hip-Hop Website Design and Development

List Taxonomy Terms based on another Taxonomy

I have a custom post type called Resources.

Resources post type has two different taxonomies associated with it, Resource Types and Resource Tags.

Resource Types sets the format/type of the resource (Guide, Article, Newsletter).

Resource Tags sets content categorization (Planning, Investing, Retirement)

On my Resource Type taxonomy page (taxonomy-resource_types.php) I want to have a list (and links for) of all of the Resource Tags for posts that match that Resource Type. It would output into the with the ID “resourceTagList”. This would act as a master list of all Resource Tags used in this specified Resource Type. These would then be used as a filtering mechanism on the site.

For example, on the Articles archive page, I want to see a list of every Resource Tag that is set on any Resource that is marked as an Article.

Here is the relevant part of the code I am currently using on my Resource Type taxonomy page:

<?php if (have_posts()) { ?>
  <div id="tagList">
    <h6>Filter by:</h6>
      <ul id="resourceTagList">
        <li><a href="">All</a></li>
        <?php //list taxonomy terms
        $terms = get_terms( 'resource_tags' );
        foreach ( $terms as $term ) {
          // The $term is an object, so we don't need to specify the $taxonomy.
          $term_link = get_term_link( $term );
          // If there was an error, continue to the next term.
          if ( is_wp_error( $term_link ) ) {
            continue;
          }
          // We successfully got a link. Print it out.
          echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></li>';
        } ?>
      </ul>
    </div>
  <div id="restList">
    <?php while (have_posts()) :
      the_post(); ?>
      <div class="resListing">
        <div class="resText">
          <h2><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h2>
          <?php the_excerpt(); ?>
        </div>
        <div class="resButton">
          <a href="<?php echo get_permalink(); ?>" class="blueButton">Learn More</a>
        </div>
      </div>
    <?php endwhile; ?>
  </div>   
<?php }else{ ?> 
  <h1>No Resources Found</h1>
<?php } ?>

This will output a list of links for every single Resource Tag that has any post attached to it, but this doesn’t also check the Resource Tag against the Resource Type.

Unfortunately, I’m unsure where to go from here to make this happen, so hopefully someone here has experienced this before.