to try
foreach($terms as $term){ echo $term; }
you can add something to separate them, for example, $echo "," or something else, but you get the idea
You can also use this
$termsString = implode (',' , $terms); echo $termsString;
According to the request:
Terms are really an array, see for example @ProdigySim's answer on how it looks. You can actually print them for debugging purposes with var_dump or print_r , but that will not help you in a production environment.
Assuming this is not an associative array, you can find the first tag as follows:
echo $terms[0]
and the rest -
echo $terms[1]
Up to the last ( count($terms)-1 ).
The foreach function prints each one in order. The second, as you can find in the manual , simply makes one line of them.
In the end, as you requested in the comments: Just paste this.
$terms = get_the_terms( $the_post->ID, 'posts_tags' ); $termsString = implode (',' , $terms); echo $termsString;
Nanne
source share