jmccole83
2/1/2019 - 4:24 PM

WordPress - get custom field from Taxonomy

Use below snippet to get a custom field from a taxonomy, snippet queries a taxonomy and then uses a foreach to loop through each entry to return it's name and a custom field icon url.

@php $facilities_list = wp_get_post_terms( $post->ID, 'facilities' ) @endphp
@foreach ($facilities_list as $term)
  @php $tax_icon = get_field('icon', $term->taxonomy . '_' . $term->term_id) @endphp
  <span class="icon" style="background-image: url({{ $tax_icon['url'] }});" data-toggle="tooltip" data-placement="top" title="{{ $term->name }}"><span class="sr-only">{{ $term->name }}</span></span>
@endforeach