Posted By

f6design on 02/16/12


Tagged

wordpress taxonomy


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

adeg
danfolt


Wordpress: Comma separated list of taxonomy terms


 / Published in: PHP
 

Create a comma separated list of a post's custom taxonomy terms.

  1. <?php
  2. // Get a list of terms for this post's custom taxonomy.
  3. $project_cats = get_the_terms($post->ID, 'TAXONOMY_NAME');
  4. // Renumber array.
  5. $project_cats = array_values($project_cats);
  6. for($cat_count=0; $cat_count<count($project_cats); $cat_count++) {
  7. // Each array item is an object. Display its 'name' value.
  8. echo $project_cats[$cat_count]->name;
  9. // If there is more than one term, comma separate them.
  10. if ($cat_count<count($project_cats)-1){
  11. echo ', ';
  12. }
  13. }
  14. ?>

Report this snippet  

You need to login to post a comment.