Support

Account

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.