Home Forums Front-end Issues Using wp_get_attachment_image with ACF on Custom Taxonomy


Using wp_get_attachment_image with ACF on Custom Taxonomy

  • I am trying to use wp_get_attachment_image with a custom taxonomy and ACF but I cannot get it to work. Below is the code I am using and I cannot figure out what is wrong with it. $attachment_id is pulling in the full path to the image url but the idea is to get the image url to the sm_thumb size and not the full sized image. Any thoughts on what I am doing wrong here?

    <ul id="product-index-cat-list">
    <?php $args = array('taxonomy' => 'product_categories', 'parent' => 0);
    $categories = get_categories($args);
    foreach($categories as $category) {
    $attachment_id = get_field('product_tax_image', 'product_categories_'.$category->term_id);
    $size = "sm_thumb";
        <li class="sixcol">
           <div class="top-category">
              <h2><a href="<?php echo get_term_link($category); ?>"><?php echo $category->name;?> </a></h2>
                    <?php // echo $category->description; ?>
                <?php /*    <a href="<?php echo get_term_link($category); ?>"><img src="<?php the_field('product_tax_image', 'product_categories_'.$category->term_id); ?>" /></a> */?>
                    <?php echo wp_get_attachment_image( $attachment_id, $size );?>
                    <?php echo $attachment_id ;?>
    <?php } ?>
  • Figured it out. The code is fine I just had to go into the custom fields admin page and chanage the “Return Value” from image URL to image ID.

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

You must be logged in to reply to this topic.