Support

Account

Home Forums Front-end Issues Displaying field with get_terms Reply To: Displaying field with get_terms

  • Hey Wozzal, I was having the same issue and my work around for now was this was really close to your code:

    <?php // Get the taxonomy's terms
    $terms = get_terms(
        array(
            'taxonomy'   => 'news_categories',
            'hide_empty' => false,
        )
    );
    ?>
    <?php // Check if any term exists
        if ( ! empty( $terms ) && is_array( $terms ) ) {
            // Run a loop and print them all
            foreach ( $terms as $term ) { ?>
           
    
                <a href="<?php echo esc_url( get_term_link( $term ) ) ?>">
                    <?php echo $term->name; ?>
                    <?php echo the_field( 'banner_text', $term ); ?>
                    <img src="<?php echo the_field( 'banner_image', $term ); ?>">
                </a>
    
    <?php       
            }
        } 
    ?>

    Getting the Term Name and URL was easy. Getting a simple field, like a “Text Field” from ACF was straight forward too using something like:

    <?php echo the_field( 'banner_text', $term ); ?>

    I really wanted to use an array for the image but that didn’t want to work so I opted for image URL instead as my work around and just echoed this with no var:

    <img src="<?php echo the_field( 'banner_image', $term ); ?>">

    If you did ever figure out how to do this with the Image Array please let me know.
    Thanks!
    Andy