Support

Account

Home Forums Front-end Issues Using ACF to show an image assigned to a taxonomy

Unread

Using ACF to show an image assigned to a taxonomy

  • Hi there,

    Let me preface this with the fact that I’m a novice with very little php understanding, and I very much appreciate any insight and help you can give.

    I have a custom taxonomy type that also has images assigned to each single taxonomy (using another plugin). On the post types that use this taxonomy, I can call the set image with:

              $terms = get_the_terms( $post->ID , 'resource_themes' );
                                  foreach ( $terms as $term ) {
                                    if (function_exists('get_wp_term_image'))
                                    {
                                    $meta_image = get_wp_term_image($term->term_id);
                                    $term_link = get_term_link($term);
                                  echo '<a href="'.$term_link.'"><div class="theme-icon-wrapper"><img src="'.$meta_image.'" class="theme-image"></div></a>';
                                  }
                                }
                              ?>

    And this is good! However, I have another page outside of this that I want to show a selected taxonomy image from. In ACF I have a taxonomy field built and pointed to ‘resource_themes’; (and within ACF it is a sub field labelled ‘theme_designation’). Now, when I try to modify my code to call the image, it does not work. Sometimes if I mess around can get it to output the taxonomy ID (Eg: 32), but that’s about it. The code I am using is as follows:

            <?php 
          $terms = the_sub_field('theme_designation');
                                foreach ( $terms as $term ) {
                                  if (function_exists('get_wp_term_image'))
                                  {
                                  $meta_image = get_wp_term_image($term->term_id);
                                  $term_link = get_term_link($term);
                                echo '<a href="'.$term_link.'"><div class="theme-icon-wrapper"><img src="'.$meta_image.'" class="theme-image"></div></a>';
                                }
                              }
                          ?>

    Can anybody help? I know it’s very likely I am doing this quite wrong. Thanks so much, again – your time is very much appreciated.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.