Bricks Condition: Check Repeater
Check if ACF repeater has rows and content. Used for bricks display conditions.
Information
After putting the below code into your function.php or a snippet manager we can use it within the bricks condition builder by selecting the dynamic data condition and using
echo:repeater_has_content(‘repeater_field’,’repeater_subfield’)
== true
(make sure to wrap that echo in {} in order for it to work in the builder)
You will notice the dynamic tag has two arguments our repeater field first and then a field within the repeater we want to check has content. You will have to switch those out with your own field names. We can use this to show content based on if a repeater has content or not.
function brx_repeater_has_content($repeater_field, $subfield) {
// Get all rows of the repeater field
$rows = get_field($repeater_field);
// Check if $rows is an array and not empty
if (!is_array($rows) || empty($rows)) {
return false;
}
// Loop through each row
foreach ($rows as $row) {
// Check if the subfield exists and is not empty
if (isset($row[$subfield]) && !empty($row[$subfield])) {
return true;
}
}
// If no content found, return false
return false;
}
14 Day Money Back
If the component doesn’t work as expected or wasn’t what you thought it was you have 14 days from the date of purchase to submit a support request and I will refund you the full amount. NO QUESTIONS ASKED.