Get the ‘slug’ of a custom taxonomy

You can do something like the following:

$terms = get_the_terms( $post->id, 'genre' ); // get an array of all the terms as objects.

$terms_slugs = array();

foreach( $terms as $term ) {
    $terms_slugs[] = $term->slug; // save the slugs in an array
}

Leave a Comment