Support

Account

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.