I have an ACF setup where a repeater is nested inside another repeater.
In the template designer, I can not currently get to the nested repeater in the visibility conditions dialog (see image attached). After selecting the first repeater, the next dialog only allows me to select inner fields not the nested repeater.
Thank you for your response, I also tried that, but I’m not able to select the repeater in that ACF dropdown. That would have worked, but the repeater doesn’t appear as an option (see image).
I might have misunderstood, as if we’re talking about a nested repeater, you would be testing for empty fields (repeated).
Something like this should do the trick (roughly set out, you might want to break out early, remove unnecessary steps if already valid etc…), AI commented. It will check if there is at least one repeated field that has a value.
/**
* Check if a repeater field has any value for a specific sub field.
*
* @param string $field_name The name of the repeater field.
* @param string $sub_field_name The name of the sub field to check for value.
* @return bool True if the repeater field has a value for the specified sub field, false otherwise.
*/
function acf_repeater_has_value( $field_name, $sub_field_name ) {
$has_value = false; // Initialize variable to track if the repeater field has any value
// Check if there are any rows in the repeater field
if ( have_rows( $field_name ) ) {
// Loop through each row of the repeater field
while ( have_rows( $field_name ) ) {
the_row();
// Check if the current sub field within the repeater has a value
if ( get_sub_field( $sub_field_name ) ) {
$has_value = true; // Set to true if a value is found
}
}
}
return $has_value; // Return whether the repeater field has any value for the specified sub field
}
Is it on the roadmap to be able to use visibility conditions with nested repeaters any time soon? If not, does any one have some direction on how to use @Louis provided function return code above?