Title: get_the_terms problem
Last modified: August 20, 2016

---

# get_the_terms problem

 *  [petershep](https://wordpress.org/support/users/petershep/)
 * (@petershep)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/get_the_terms-problem/)
 * Hello,
 * I’m basically after the first term for a post that isn’t equal to any of the 
   ids listed.
 * I’ve checked the loop by outputting the $term_id and $term_parent for different
   posts which have the same terms so I can see that the if statement is being passed
   the same values.
 * But here’s the problem, for the same $term_id and $term_parent values sometimes
   the $term_link_content variable has content and other times it’s empty!…
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome#Posting_Code).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * Many thanks for any advice

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

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/get_the_terms-problem/#post-2218869)
 * First of I don’t think you can pass “product_categories” as an argument for get_posts().
   Can you explain your problem a bit more.
    Is the if else statement not working
   the way you want? maybe:
 *     ```
       if(($term_id != 114 && $term_parent != 83) || ($term_id != 115 && $term_parent != 83)) { ... } else { ... }
       ```
   
 *  Thread Starter [petershep](https://wordpress.org/support/users/petershep/)
 * (@petershep)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/get_the_terms-problem/#post-2218880)
 * Thanks for you response. But I’ve figured it out. I am using the $term_link_content
   outside of the loop so sometimes it would register a value for the variable but
   then the next loop through would empty it!!
 * So stoopid!
 * But I did find someone using the taxonomy name with get_posts() as the only way
   to grab a specific term for a custom taxonomy.
 * Cheers
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/get_the_terms-problem/#post-2218887)
 * get_posts() makes use of the WP_Query class to fetch posts. So you can use taxonomy
   parameters: [http://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters](http://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters)
 * And I think it needs the taxonomy ID or slug like `taxonomy=best-sellers` if 
   best-sellers is the name you registered this taxonomy with.

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

The topic ‘get_the_terms problem’ is closed to new replies.

## Tags

 * [get_the_terms](https://wordpress.org/support/topic-tag/get_the_terms/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/get_the_terms-problem/#post-2218887)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
