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
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