How to get a taxonomy term name by the slug?

The function you are looking for is get_term_by. You would use it as such:

<?php $term = get_term_by('slug', 'my-term-slug', 'category'); $name = $term->name; ?>

This results in $term being an object containing the following:

term_id
name
slug
term_group
term_taxonomy_id
taxonomy
description
parent
count

The codex does a great job explaining this function: https://developer.wordpress.org/reference/functions/get_term_by/

Leave a Comment