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
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 repeater_has_content($repeater_field, $subfield) {
// Check if the repeater field has any rows
if (have_rows($repeater_field)) {
// Loop through the rows
while (have_rows($repeater_field)) {
// Set the current row as active
the_row();
// Get the value of the sub-field
$subfield_value = get_sub_field($subfield);
// Check if the sub-field has content
if (!empty($subfield_value)) {
// If it has content, return true
return true;
}
}
}
// If no rows found or no sub-field has content, 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.