Support

Account

Home Forums Add-ons Repeater Field Return taxonomy image URL in repeater

Helping

Return taxonomy image URL in repeater

  • Hi,

    I am trying to retrieve the image URL of a taxonomy which is selected from a taxonomy custom field, but I can’t seem to get it to work.

    This is the custom field:

    Custom field

    And this is the code I currently have:

    <article class="home__categories">
      <div class="container">
        <div class="row">
    
          <?php if( have_rows('hp_prodcat') ):
            while( have_rows('hp_prodcat') ): the_row();
              $hpcProdcat = get_sub_field('hp_prodcat_cat');
              $hpcName = get_sub_field('hp_prodcat_display_name');
            ?>
    
              <div class="col-2">
                <img src="<?php echo wp_get_attachment_url($hpcProdcat); ?>" alt="">
                <a href="<?php echo get_term_link($hpcProdcat); ?>"><?php echo $hpcName; ?></a>
              </div>
    
            <?php endwhile;
          endif; ?>
    
        </div>
      </div>
    </article>

    I only started PHP a few months ago, this is where my knowledge stops 🙂 Looked up the documentation and the other threads, but couldn’t find anything to solve this for me.

  • You need to get the value of the image field from the term

    
    $image = get_field('your image field name here', 'term_'.$hpcProdcat);
    

    this is explained in the “get a value from different objects” section of this page https://www.advancedcustomfields.com/resources/get_field/

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.