Check this function: wp_get_post_terms()
Assuming your post supports two taxonomies called tax_a
and tax_b
, you can try something like this, exactly where you wrote your comment:
<?php $terms = wp_get_post_terms( $query->post->ID, array( 'tax_a', 'tax_b' ) ); ?>
<?php foreach ( $terms as $term ) : ?>
<p><?php echo $term->taxonomy; ?>: <?php echo $term->name; ?></p>
<?php endforeach; ?>
This will print all the terms for each post retrieved by the query.
EDIT
If what you want is all the terms in all the posts retrieved by the query, you can store the values in an array and then use a function like array_unique(), like this:
$all_terms = array();
foreach ( $terms as $term ) {
$all_terms[] = $term->name;
}
// ... and outside the WHILE loop
$result = array_unique( $all_terms );
foreach ( $result as $term ) {
echo $term . '<br/>;
}