ACF: Display Category Name Using Taxonomy Field

The Advanced Custom Field plugin’s Taxonomy field type has been giving me a hard time for several hours now … This plugin is so versatile, that there is simply not enough documentation on the website, despite all of the amazing work done by Elliot Condon.

ACF Taxonomy Field Type

I’m using the Taxonomy field type on a membership site to bring categories into the User profiles and select the values via Gravity Forms User Registration add-on.

The Taxonomy categories then need to be displayed within the profile pages on the front end AND within the Category template to filter through users within the selected taxonomies.

I could not get these categories to display anything other than IDs on the front end.

Thanks to information found here, I was able to echo out the category values onto the front end within the loop.

Original:

$term = get_sub_field('category_selector'); 
if( $term ) {
  foreach($term as $t) {
    $t = get_category($t);
    echo $t->name;
  }
}

Customized User Specific:

$author_id = get_the_author_meta('ID');

$term = get_field('custom_field', 'user_'. $author_id); // add author's ID to the user field
if( $term ) {
  foreach($term as $t) {
    $t = get_term($t);
    echo $t->name; // this can be changed to slug if necessary
  }
}

2 thoughts on “ACF: Display Category Name Using Taxonomy Field

    1. Hey Andy,

      Sorry for the delay! You place this code in your template where you would like to show the categories. The layout may differ based on what you’re trying to accomplish.

      Hope that helps!

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.