Home › Forums › Add-ons › Repeater Field › Accessing sub fields from multiple repeaters › Reply To: Accessing sub fields from multiple repeaters
There isn’t a way to do this using have_rows loops. To do this you would need to get both of the repeater fields as arrays and loop through them, something like
$regular = get_field('breakfast_mf_regular_price');
$special = get_field('breakfast_mf_special_price');
both of these will hold an array of rows. But since there’s no guarantee that the rows of the second repeater will align with the rows of the first repeater, there really isn’t going to be an easy way to check to see which value you should use.
Basically you need to loop through one of them and then loop through the other. This is a really basic example of plucking one sub field out of one of two arrays.
foreach ($regular as $r_row) {
$price = $r_row['price'];
foreach ($special as $s_row) {
if ($r_row['name'] == $s_row['name']) {
$price = $s_row['price'];
}
}
}
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.