Title: Taxonomy Query
Last modified: August 21, 2016

---

# Taxonomy Query

 *  [thoughtwell](https://wordpress.org/support/users/thoughtwell/)
 * (@thoughtwell)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/taxonomy-query-1/)
 * I have a single custom post type of ‘products’ while that cpt is organized by
   5 taxonomy categories which include ‘equipment’, ‘tools’ and ‘supplies’.
 * On my single-equipment.php page (single custom post type template page) I would
   like to show ‘related-items’ where the page pulls other items from the related
   taxonomy shown on the given page. In a sense, it’s basically a “see more items
   like this one” type of thing.
 * So let’s say a viewer is looking at a page for ‘window cleaner fluid’ that belongs
   to the category/taxonomy of ‘supplies’, I want to have 3 or 4 items pull from
   the ‘supplies’ taxonomy to show at the bottom of the post before the footer.
 * So far, I have the following:
 *     ```
       function smt_related_items() {
   
         $terms = get_the_terms( get_the_ID());
         $args = array(
           'posts_per_page' => 4,
           'post__not_in' => array( get_the_ID() ),
           'category_name' => $terms[0]->slug
         );
         $loop = new WP_Query( $args );
   
         if( $loop->have_posts() ):
           echo '<div class="related-items"><h3>Related Items from Summit</h3>';
           while( $loop->have_posts() ): $loop->the_post();
             $classes = 'one-half relate-box';
             if( 0 == $loop->current_post || 0 == $loop->current_post % 2 )
               $classes .= ' first';
             echo '<div class="' . $classes . '"><a href="' . get_permalink() . '">' . get_the_post_thumbnail( get_the_ID(), 'pdt-thumb' ) . '</a><p>' . get_the_excerpt() .'</p></div>';
           endwhile;
           echo '</div>';
         endif;
         wp_reset_postdata();
   
       }
       ```
   
 * but my page simply seems to only return 4 posts from wherever on the site, including
   from the normal posts categories with no distinguishing on where it’s pulling
   posts from. I’ve been stuck on this for like 3 days, and I can’t figure it out.
 * Can anyone help!?

The topic ‘Taxonomy Query’ is closed to new replies.

## Tags

 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [taxonomy](https://wordpress.org/support/topic-tag/taxonomy/)

 * 0 replies
 * 1 participant
 * Last reply from: [thoughtwell](https://wordpress.org/support/users/thoughtwell/)
 * Last activity: [12 years, 8 months ago](https://wordpress.org/support/topic/taxonomy-query-1/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
