Title: Get terms for array of posts
Last modified: August 20, 2016

---

# Get terms for array of posts

 *  [capcar](https://wordpress.org/support/users/capcar/)
 * (@capcar)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/get-terms-for-array-of-posts/)
 * Greetings all, I am using WordPress posts to create a huge collection of vendor
   pages, and these pages are tagged with 2 different taxonomies: location and service.
   The taxonomies are working wonderfully by themselves, however, I now need the
   ability to cross-reference them. In other words, if someone clicks the listing
   for Alabama, I want a list of service tags that can narrow down that listing 
   further.
 * My question is: If there a way to create an array of only the terms that are 
   attached to the the posts in the current “query_posts()” set? In this example,
   I don’t want to list every service tag again (there are hundreds), I only want
   those that are pertinent to the current “Alabama” set.
 * For example, if I have the following posts:
 * Alabama Post 1: tagged with Kitchen, Garage
    Alabama Post 2: tagged with Kitchen,
   Bedroom Alabama Post 3: tagged with Office, Closet
 * …I am looking to create a term array that only contains:
 * Kitchen, Garage, Bedroom, Office, Closet
 * I feel this solution is just barely eluding me and would appreciate your input.
   Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/get-terms-for-array-of-posts/#post-2661331)
 * I have not tested this, but this is my first thought:
 * Loop through the posts and collect an array of IDs, then do a query on the service
   tag using a posts__in parameter.
 *  Thread Starter [capcar](https://wordpress.org/support/users/capcar/)
 * (@capcar)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/get-terms-for-array-of-posts/#post-2661344)
 * Thought about doing this, but the results are paginated, so I can’t loop through
   the full results on one page… though I guess I could run the loop twice – once
   just to collect the ID’s on a full result.
 * In the end, I chose to make a custom SQL query – basically taking the page query(
   which I got using $GLOBALS[‘wp_query’]->request) and creating a SELECT statement
   for the terms whose relationship ID’s that are IN that query. Runs rather slow,
   however, so I may try your suggestion. Thanks!
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/get-terms-for-array-of-posts/#post-2661345)
 * Rather than retrieving the entire posts with your custom query, just select the
   ID. That should run faster.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Get terms for array of posts’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/get-terms-for-array-of-posts/#post-2661345)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
