wordpress - Using an ACF image object for a custom taxonomy within an echo block loop -


i can't seem pull acf image object custom taxonomy when used in loop, made of echo blocks:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); $terms = get_terms( 'product_type' ); $image = get_field('product_type_tax_image'); $hero_image = $image['sizes']['medium'];  foreach ( $terms $term ) {  // $term object, don't need specify $taxonomy. $term_link = get_term_link( $term );  // if there error, continue next term. if ( is_wp_error( $term_link ) ) {     continue; } var_dump($hero_image); // got link. print out. echo '<a href="' . esc_url( $term_link ) . '" class="product-grid- block" style="' . $hero_image[0] . '">'; echo '<div class="product-grid-inner-txt-wrap">'; echo '<h4>' . $term->name . '</h4>'; echo '<p>' . $term->description . '</p>'; echo '</div>'; echo '</a>'; } ?>  <?php endwhile; endif; ?> <?php wp_reset_query(); ?> 

the var dump returns null. i've looked @ this , this don't seem help. doing wrong?

take @ article:

http://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/

to pull custom field taxonomy term, need add second item get_field function call. this:

$image = get_field('product_type_tax_image', $term );

also, looks you're trying loop through $terms, you're grabbing custom field's value outside of foreach loop, should moved inside loop, so:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post();     $terms = get_terms( 'product_type' );       foreach ( $terms $term ) {     //get $term's image     $image = get_field('product_type_tax_image', $term );     $hero_image = $image['sizes']['medium'];      // $term object, don't need specify $taxonomy.     $term_link = get_term_link( $term );      // if there error, continue next term.     if ( is_wp_error( $term_link ) ) {             continue;     }     var_dump($hero_image);     // got link. print out.     echo '<a href="' . esc_url( $term_link ) . '" class="product-grid- block" style="' . $hero_image[0] . '">';     echo '<div class="product-grid-inner-txt-wrap">';     echo '<h4>' . $term->name . '</h4>';     echo '<p>' . $term->description . '</p>';     echo '</div>';     echo '</a>';     }     ?>      <?php endwhile; endif; ?>     <?php wp_reset_query(); ?> 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -