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!
Plugin boilerplates can do some of the heavy lifting during initial development. We look at four options to speed up your plugin creation. https://t.co/ZtMsdBxAHw
— Advanced Custom Fields (@wp_acf) June 5, 2023
© 2023 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.