I have a custom post type called 'classe'. I am trying to loop through each of these posts to get a list of their taxonomies and their terms. Here is my code :

$type = 'classe';
    $args = array(
        'post_type' => $type,
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'ignore_sticky_posts'=> true

    $loop = null;
    $loop = new WP_Query($args);

    if( $loop->have_posts() ):
        while ($loop->have_posts()) : $loop->the_post();

            $taxonomies = ???? //Get taxonomies

            $result = '<div class="col-xs-12 col-md-4">';
                $result .= '<div class="grid-content">';
                $result .= '<h2>' . get_the_title() .'</h2>';
                $result .= '<p>' . get_the_excerpt() .'</p>';
                foreach($taxonomies as $taxonomy){
                    $terms = ???? //Get terms
                    $result .= '<h4>' . $taxonomy . '</h4>';
                    foreach($terms as $term){
                        $result .= '<p>' . $term . '</p>';
                $result .= '</div>';
            $result .= '</div>';
            echo $result;

You can use the function wp_get_post_terms to retrieve the terms of the post you're looping through.

$taxonomies = wp_get_post_terms(get_the_ID(), 'taxonomy-name');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.