Retrieve ACF fields attached to categories, tags, and custom taxonomy terms using the term ID prefix.
ACF uses a special term_{id} format for the $post_id parameter when working with taxonomy terms:
<?php
// Get a field from a specific term.
$term_id = 42;
$color = get_field( 'brand_color', 'term_' . $term_id );
$icon = get_field( 'icon', 'term_' . $term_id );
Display fields for the current category on an archive page:
<?php
$term = get_queried_object();
if ( $term instanceof WP_Term ) {
$description = get_field( 'custom_description', $term );
$image = get_field( 'featured_image', $term );
if ( $image ) {
echo wp_get_attachment_image( $image, 'medium' );
}
if ( $description ) {
echo '<div class="term-description">' . wp_kses_post( $description ) . '</div>';
}
}
Loop through all terms and display their ACF fields:
<?php
$terms = get_terms( [
'taxonomy' => 'product_category',
'hide_empty' => false,
] );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
$icon = get_field( 'icon', $term );
echo '<div class="category-card">';
echo '<h3>' . esc_html( $term->name ) . '</h3>';
if ( $icon ) {
echo '<img src="' . esc_url( $icon['url'] ) . '" alt="' . esc_attr( $icon['alt'] ) . '" />';
}
echo '</div>';
}
}
Note: You can also pass the WP_Term object directly to get_field() instead of the string prefix — ACF will resolve it automatically.