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(); ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Our guide looks into WordPress custom fields and how they stack up against the possibilities of ACF.
— Advanced Custom Fields (@wp_acf) July 18, 2022
https://t.co/hk3yibkHyk
© 2022 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.