Home › Forums › General Issues › Get specific sub group and count word occurrences in foreach loop › Reply To: Get specific sub group and count word occurrences in foreach loop
I’ve also tried using the have_rows method as seen below, no luck.
function show_status() {
$field_group_key = 'group_65e26ad7b9a44';
$fields = acf_get_fields($field_group_key);
$open_count = 0;
$total_fields = count($fields);
foreach ($fields as $field) {
if (have_rows($field)) {
while (have_rows($field) ) {
the_row();
$status = get_sub_field('status');
foreach ($status as $checkbox_value) {
if (stripos($checkbox_value, 'Open') !== false) {
$open_count++;
break;
}
}
}
}
}
return "Runs {$open_count}/{$total_fields} open";
}
// Register the shortcode
add_shortcode('show_the_status', 'show_status');
Nothing I have tried will seem to grab onto the sub field status and parse the checkbox array and up the counter.
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.