I am trying to get all taxonomy names of a speicific custom type.
In the stackoverflow archive I found the script below for a single postID. I would like to loop all taxonomy names of a single custom post type and not just one with the id.
Taxomy should be: my_tax and the custom post type: my_team
$terms = get_the_terms( $post->ID, 'my_tax' );
foreach($terms as $term) {
echo $term->name;
}
Such code can be:
$type = 'my_team';
$args = array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => -1,
);
$my_query = null;
$my_query = new WP_Query($args);
if ($my_query->have_posts()) {
while ($my_query->have_posts()) {
$post = $my_query->the_post();
$terms = get_the_terms( $post->ID, 'my_tax' );
foreach($terms as $term) {
echo $term->name;
}
}
}
wp_reset_query(); // Restore global post data stomped by the_post().