Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Goodnight

Comma separated list of taxonomy terms

SnippetsWordPress

About a 1 minute read

"We cannot solve our problems with the same thinking we used when we created them."

Albert Einstein


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