Support

Account

Home Forums Add-ons Repeater Field ACF foreach for loop, content being repeated for each custom taxonomy Reply To: ACF foreach for loop, content being repeated for each custom taxonomy

  • Solved my own problem:

    <?php
    /*
      Template Name: Assets Template
    */
    get_header(); ?>
    
              <h1><?php echo get_the_title(); ?></h1>
    
              <hr>
    
              <!-- Start the Loop. -->
              <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
                <div class="controls">
                  <?php
                    $terms = get_terms( 'asset-categories', array('hide_empty' => false) );
                    $filter_links = array();
                    foreach ( $terms as $term ) {
                      $filter_links[] = '<button class="filter" data-filter=".'.$term->name.'">'.$term->name.'</button>';
                    }
                    $on_filter = join( "", $filter_links );
                  ?>
                  <label>Filters: </label><button class="filter" data-filter="all">All</button><?php echo $on_filter; ?>
    
                </div><!-- end .controls -->
                <div class="clear"></div>
    
                <div id="downloads-container">
                  <div class="container">
    
                    <?php
                      $rows = get_field('asset');
     
                      if($rows) {
     
                        foreach($rows as $key => $row) {
                          $column_id[$key] = $row['id'];
                        }
                        array_multisort($column_id, SORT_ASC, $rows);
     
                        $i = 0;
                        foreach($rows as $row) {
                            $taxonomyterm="";
                            for($i = 0; $i < count($row['category']); $i++) {
                                    $taxonomyterm = $taxonomyterm . $row['category'][$i] -> name . ' ';
                            }
                          echo '<div class="mix img ' . $taxonomyterm . '">' . (($row['image'])?) . '<img src="' . $row['image'] . '"/><h4>' . $row['name'] . '</h4>' . $row['description'] . '<div class="overlay"><a href="' . $row['file'] . '" class="expand" download>↓</a><a class="close-verlay hidden">x</a></div></div>';
                          $i++;
                        }
                      }
                    ?>
                  </div>
                  <div class="gap"></div>
                  <div class="gap"></div>
                </div>
    
                <?php endwhile; else : ?>
    
                  <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    
              <?php endif; ?>
    
    <?php get_footer(); ?>