0
votes

I'm facing an issue with my website. I would like to display all my custom post type named "Projets", and for each item, I want to get several term names to put in my data element.

Displaying all my post is not an issue, it's working well. I manage to display one term name using "get_terms()", but I don't know how to display several terms and put them in the right place. I have 3 different custom taxonomy : city, typo and statut.

There is my code :

 <?php
    $args = array(
        'post_type' => 'projets', 
        'posts_per_page'=>'99',
        'order' => 'ASC',
    );

    $loop = new WP_Query( $args );

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

    <li class="content_item active" data-city="CITY_NAME_HERE" data-typo="TYPO_NAME_HERE" data-statut="STATUT_NAME_HERE">
    
        <a href="<?php the_permalink(); ?>">
            <?php the_post_thumbnail('custom-size', ['class' => 'content_item_img', 'title' => 'Image du projet']); ?>
            <h4><?php the_title(); ?></h4>
        </a>
    </li>

<?php endwhile; 
wp_reset_postdata(); 
?>

Thanks for the help!

2

2 Answers

0
votes

Try this:

Inside the loop, you get the taxonomy like this (eq. "city"):

$cities = get_terms( array(
    'taxonomy' => 'city',
    'hide_empty' => false,
) );

You get an array of all the terms of the Taxo. Where you need them, you have to loop them, here to give you an idea.

if(!empty($cities)){
    foreach($cities as $city){
        echo $city->name.', ';
    }
}else{
    echo 'No Cities.';
}
0
votes

Comma Separated custom categories inside the loop.

<?php echo get_the_term_list( $post->ID, 'cutom_category', '', ', ', '' ) ?>