stein
November 29, 2022, 9:12am
1
I cannot get conditions to work when targeting an ACF repeater field (row) or an ACF sub field.
Targeting the native WP custom field works, ala; {cf_sh_avstander} instead of {acf_sh_avstander}.
See attached image. For illustration purposes, I’ve set them both up, but only the top one actually works.
timmse
November 30, 2022, 5:34pm
2
Hi Stein,
Thanks so much for your report!
Which version are you currently using? Please edit your report and add the version number.
However, I was able to reproduce the issue. Checking the ACF repeater values requires using the ACF have_rows() function, so comparing to empty, null or similar doesn’t work in this case.
Best regards,
timmse
3 Likes
timmse
December 6, 2022, 11:52am
3
Hey Stein,
Quick question: do you query the ACF repeater with a loop on the page? If not, you should try that. Then the conditions should work
stein
December 13, 2022, 7:00pm
4
Hello timmse,
Thank you for looking into it.
I’m not sure I understand what you mean Could you elaborate?
Stein
I thought we can check repeater field like that too, but apparently not:
November 26, 2022 / 0 comments / Favorite Checking for ACF Repeater Rows in Bricks Sridhar Katakam Categories: Bricks , Free , Plugins Tags: ACF , ACF Repeater
timmse
December 14, 2022, 4:40pm
6
To be able to use the ACF repeater values, you must query them with a query loop, otherwise they are not available and therefore cannot be used in the conditions. This is our variant of the ACF have_rows() function.
So: Add an ACF Repeater query loop so that the entries are queried and accordingly available, and test the condition again.
Note, the solutions provided do not work for nested repeaters in my current situtation.
I have:
I wanted to apply the conditional statement to the “DIV wrapper”. I cannot set this as a query loop, as suggested.
I tried a bunch of stuff, and eventually tried this:
/*
* Check if nested ACF repeater has fields
*
* @access public
* @param string $parent Parent repeater field slug
* @param string $child Child repeater field slug
* @return boolean True if repeater has rows
*/
function custom_acf_nested_repeater_check($parent, $child)
{
// if ACF is not active, return false
if (!class_exists("ACF")) {
return false;
}
// Bricks loop index, to simulate ACF row
$row = intval( Bricks\Query::get_loop_index() ) + 1;
if (have_rows($parent)):
while (have_rows($parent)):
the_row();
// ACF row index
$subRow = get_row_index();
// Check and return true if nested repeater has fields
if (($subRow === $row) && have_rows($child)):
return true;
break;
endif;
endwhile;
endif;
return false;
}
This does not work with the conditional feature within Bricks, I have no idea why.