Home › Forums › Add-ons › Repeater Field › Combine 2 repeater rows with same values › Reply To: Combine 2 repeater rows with same values
Thanks, what I mean is to combine two arrays (captured from two different acf repeater rows), so that they combine and can be sorted alphabetically.
Each repeater has these fields
$this_array = repeater fields $arg1 and $arg2
$that_array = repeater fields $arg1 and $arg2
$result = array_merge_recursive($ar1, $ar2);
sort($result);
This sample does note combine them and display them alphabetically:
<?php
$this_array = get_field('this_array');
$that_array = get_field('that_array');
?>
<ul class="panel">
<?php if( have_rows('this_array') ): ?>
<?php while ( have_rows('this_array') ) : the_row();
$arg1 = get_sub_field('arg1');
$arg2 = get_sub_field('arg2');
?>
<li><?php the_sub_field('arg1') ?><span>
<?php the_sub_field('arg2') ?></span></li>
<?php endwhile; ?>
<?php else : // no rows found
endif; ?>
<?php if( have_rows('that_array') ): ?>
<?php while ( have_rows('that_array') ) : the_row();
$arg1 = get_sub_field('arg1');
$arg2 = get_sub_field('arg2');
?>
<li><?php the_sub_field('arg1') ?><span>
<?php the_sub_field('arg2') ?>
</span></li>
<?php endwhile; ?>
<?php else : // no rows found
endif; ?>
</ul>
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!
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.