How to separate terms name with comma in an array? - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Tuesday, March 29, 2022

How to separate terms name with comma in an array?

I am trying to get taxonomies terms names separated with a comma. This is the code, but it separates taxonomies and terms with : If there are many terms they get separated with : instead of , If I delete the : symbol there are nothing in between taxonomy terms names.

<ul class='apt-product-terms'>
      <?php
        $_taxonomies = array(
            'taxname1'   =>   __( 'Taxname1', 'textstringdomain' ),
            'taxname2'   =>   __( 'Taxname2', 'textstringdomain' ),
            'taxname3'   =>   __( 'Taxname3', 'textstringdomain' ),
            'taxname4'   =>   __( 'Taxname4', 'textstringdomain' )
        );
 

        foreach ($_taxonomies as $taxonomy_slug => $taxonomy_name) {
          $terms = get_the_terms( $post->ID, $taxonomy_slug);
          if (is_array($terms) && count($terms) > 0) {
      ?>

      <li class='apt-tax-item'>
        <span class='apt-term-name'><?php echo $taxonomy_name  ?></span>
        <ul class='apt-tax-term-list'>
        <?php
          foreach ( $terms as $term ) {

          ?>
            <li class='apt-term-item'>: 
              <a class='apt-term-link' href="<?php echo get_term_link($term); ?>"> <?php echo $term->name ?></a>           
            </li>
          <?php
          } 
        ?>
        </ul>
      </li>

      <?php            
        }
          }  
      ?>
    </ul>

Where is the problem. I think it might be related to echo $term->name



source https://stackoverflow.com/questions/71651140/how-to-separate-terms-name-with-comma-in-an-array

No comments:

Post a Comment