0

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.

0

First get the posts that have the taxonomy you need

$posts = get_posts('resource type' => 'archive')

Then loop the results and use this function

wp_get_post_terms($post_id)

I think you got it figured out how to display your results

  • This would output a list of tags under each post listing. I am trying to generate a master list of all Resource Tags that have the specified Resource Type. The goal is to display them inside the <ul> with the id "resourceTagList". So if I am on the Articles resource type taxonomy page, I want to see a full list of every Resource Tag used across all posts with the resource type term "articles". – Joe Aug 20 '15 at 12:39
  • An using mobile so its not easy to write the code. You need two loops. Loop one get every post marked 'archive'. Loop two get every tag from the post and add its id to array. At the end of the loops remove duplicate and you will have an array of the tags used on every 'archive' – Abdullah Alsigar Aug 20 '15 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.