Home › Forums › General Issues › Check if subfield of repeater has any value, before the_row › Reply To: Check if subfield of repeater has any value, before the_row
This is where output buffers come in handy, https://www.php.net/manual/en/book.outcontrol.php. I won’t repeat your entire code here, just the basics.
<?php
// only send output if there is content
$has_content = false; // a flag to output content
ob_start(); // start output buffering
?>
<p>this content will be buffered and only output if the repeater has values.</p>
<?php
if (have_rows('repeater field')) {
while (have_rows('repeater field')) {
the_row();
if (get_sub_field('sub field name')) {
// row has content
// output the sub field
the_sub_field('sub field name');
// set flag to output content
$has_content = true;
}
}
}
// get the content of the buffer and clear it
$content = ob_get_clean();
// if the flag was set then output the content
if ($has_content) {
echo $content;
}
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.