Title: get_terms returning empty array
Last modified: August 20, 2016

---

# get_terms returning empty array

 *  Resolved [peterjharrison](https://wordpress.org/support/users/peterjharrison/)
 * (@peterjharrison)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/get_terms-returning-empty-array/)
 * Hi,
 * I’m having an issue with the get_terms() function.
 * If I use:
 *     ```
       <?php
       $terms = get_terms( 'location' );
       print_r($terms);
       ?>
       ```
   
 * I get an array back:
 * `Array ( [0] => stdClass Object ( [term_id] => 8 [name] => Aberdare [slug] =>
   aberdare [term_group] => 0 [term_taxonomy_id] => 8 [taxonomy] => location [description]
   => [parent] => 7 [count] => 1 ) [1] => stdClass Object ( [term_id] => 10 [name]
   => Aberdeen [slug] => aberdeen [term_group] => 0 [term_taxonomy_id] => 10 [taxonomy]
   => location [description] => [parent] => 9 [count] => 14 ) [2] => stdClass Object([
   term_id] => 17 [name] => Aberdeenshire [slug] => aberdeenshire [term_group] =
   > 0 [term_taxonomy_id] => 17 [taxonomy] => location [description] => [parent]
   => 9 [count] => 41 ) [3] => stdClass Object ( [term_id] => 1203 [name] => Aberdour[
   slug] => aberdour [term_group] => 0 [term_taxonomy_id] => 1203 [taxonomy] => 
   location [description] => [parent] => 446 [count] => 1 );`
 * But if I try and get the terms with the parent of of any number of child_of the
   array comes back empty.
 *     ```
       <?php
       $terms = get_terms( 'location', array('parent' => 9) );
       print_r($terms);
       ?>
       ```
   
 * I get this:
 * `Array ( )`
 * Does any one know what i’m doing wrong?
 * Thanks
    Pete

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

 *  [TCBarrett](https://wordpress.org/support/users/tcbarrett/)
 * (@tcbarrett)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/get_terms-returning-empty-array/#post-2421332)
 * Is it a hierarchical taxonomy?
 *  Thread Starter [peterjharrison](https://wordpress.org/support/users/peterjharrison/)
 * (@peterjharrison)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/get_terms-returning-empty-array/#post-2421333)
 * Do you mean, does it have parents and children?
 * Thanks
    Pete
 *  Thread Starter [peterjharrison](https://wordpress.org/support/users/peterjharrison/)
 * (@peterjharrison)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/get_terms-returning-empty-array/#post-2421344)
 * I just check and the tax ‘location’ Hierarchical is set to true.
 * Pete
 *  Thread Starter [peterjharrison](https://wordpress.org/support/users/peterjharrison/)
 * (@peterjharrison)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/get_terms-returning-empty-array/#post-2421506)
 * Ok I solved the issue.
 * Was a bit strange really. All my terms were added via a script using the wp_insert_term
   function. When I went to the edit-tags.php?taxonomy=location page in the dashboard
   could only see the top three terms in the list on the right, but I could see 
   the others in he term cloud on the left.
 * I then went into one of the terms and saved it and they all appeared in the list
   on the right hand side and also in my array.
 * I’m guessing their must of been some sort of caching on the terms list and it
   needed me to save one through the dashboard in order to see the hierarchy.
 * A strange one I must admit.
 * Pete
 *  [TCBarrett](https://wordpress.org/support/users/tcbarrett/)
 * (@tcbarrett)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/get_terms-returning-empty-array/#post-2421678)
 * It seems you’ll need to jiggle the cache yourself using [http://wpseek.com/_get_term_hierarchy/](http://wpseek.com/_get_term_hierarchy/)
 * And here’s a related stackexchange question:
    [http://wordpress.stackexchange.com/questions/15143/calling-clean-term-cache-fails-when-called-in-the-same-plugin-that-creates-ter](http://wordpress.stackexchange.com/questions/15143/calling-clean-term-cache-fails-when-called-in-the-same-plugin-that-creates-ter)

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

The topic ‘get_terms returning empty array’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [TCBarrett](https://wordpress.org/support/users/tcbarrett/)
 * Last activity: [14 years, 6 months ago](https://wordpress.org/support/topic/get_terms-returning-empty-array/#post-2421678)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
