Wordpress Development - get the terms - returns 'array'

5.4k views Asked by At

I am trying to get the terms of a specific taxonomy to display on a page. The code is located in a page template and when I use 'get_the_terms' the result that shows is 'array'. Can someone explain this?

2

There are 2 answers

0
keatch On

It's corrent. As reported in the codex page for get_the_terms() return an array of terms. You can then use the array later in your code.

Do

<?php
   $terms = get_the_terms();
   print_r($terms)
?>

to discover the structure of the terms.

This example prints out the name of the terms that are retrieved by the function.

foreach ( $terms as $term ) {
 echo $term->name
}
0
Peter Rowell On

Slightly off-topic, but just yesterday I answered a question related to this over on wordpress.stackexchange.com. It uncovered some interesting variations on the theme of "getting taxonomies/terms associated with a post".