Support

Account

Home Forums General Issues Pulling image from custom taxonomies

Solved

Pulling image from custom taxonomies

  • I created an image field and attached it to my CPT custom taxonomy. This part is working fine. The image field shows up in the backend dashboard.

    I’m trying to query the custom taxonomy to show the top level categories with images.

    Here is my function:

    function rt_product_categories() {
      $productcategories = get_terms(
        array(
          'taxonomy' => 'product_category',
          'parent'   => 0,
        )
      );
    
      if (  !empty( $productcategories ) && ! is_wp_error( $productcategories )) {
          $productcats = '<div class="aeroProducts">';
          foreach ($productcategories as $category) :
            $productcats .= '<div class="productEntry"><a href="'.esc_url( get_term_link( $category ) ).'">';
            $productcats .= '<h3>'.$category->name.'</h3>';
    	  if ( get_field('product_category_img', $category->term_id ) ) $productcats .= "there is a photo";
            $productcats .= '</a></div>';
          endforeach;
          $productcats .= '</div>';
          // Code
          return $productcats;
        } else { //end if posts
          return 'no categories available';
        }
    }

    I can’t seem to figure out how to check (and then display) the image. I’m sure I’m missing something. Any ideas what it is?

  • use

    
    get_field('product_category_img', 'term_'.$category->term_id ) 
    

    or

    
    get_field('product_category_img', $category) 
    

    or you can also use

    
    get_field('product_category_img', 'product_category_'.$category->term_id ) 
    
  • Hey thanks, My issue has resolved..

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

You must be logged in to reply to this topic.