Home › Forums › ACF PRO › ACF Taxonomy › Reply To: ACF Taxonomy
In your loop template, use the get_field() function to retrieve the custom field values for each term in the “product_categories” taxonomy. Here is an example code snippet:
<?php
$terms = get_terms( array(
'taxonomy' => 'product_categories',
'hide_empty' => false,
) );
foreach ( $terms as $term ) {
$name = get_field( 'c_name', $term );
$image = get_field( 'c_image', $term );
if ( $name ) {
echo '<h2>' . esc_html( $name ) . '</h2>';
}
if ( $image ) {
echo wp_get_attachment_image( $image, 'thumbnail' );
}
}
?>
This code snippet retrieves the “c_name” and “c_image” custom field values for each term in the “product_categories” taxonomy and displays them in the loop.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.