jeudi 12 novembre 2020

Foreach loop through cpt categories to use ACF values

I am looping through my CPT categories and I want to use my ACF field inside my for each loop.

 <div id="response">
         <?php
         $args = array(
          'post_type'  => 'segments-overview',
           'orderby' => 'date', // we will sort posts by date
           'posts_per_page' => -1
        );



        $query = new WP_Query( $args );
        $all_terms = [];
        if( $query->have_posts() ) :
          while( $query->have_posts() ): $query->the_post();

          $terms = get_the_terms(get_the_ID(), 'category-segments-overview');
          foreach($terms as $term) $all_terms[$term->term_id] = $term;

          endwhile;

          foreach($terms as $term):
            ?>

          <div class="segments-card">
            <div class="img">image</div>
            <div class="content">
                <div class="title"><?php echo $term->name; ?></div>
                
                // ACF field
                <?php echo the_field('product', $term->taxonomy) ; ?>

                <a class="button transparent" href="/segments/<?php echo $term->slug; ?>">
                <?php echo __('View All','axia'); ?>
              </a>
            </div>
            </div>
          </div>

        <?php endforeach;

          wp_reset_postdata();
        else :
          ?>
          <div class="no-posts-found">
            <h2>There were no items found</h2>
              <h3>Please try a different search</h3>
          </div>
          <?php
        endif;
          ?>
    </div>

Can anyone tell me how to retrieve my value of my "products" field inside the foreach loop. For now i do not recieve any errors, but i also do not recieve any value.

please help.

Aucun commentaire:

Enregistrer un commentaire