How can I count ACF sub_field with a certain value
PHP’s count() function is generally used to count elements in an array, but you’re counting the value of a string, and that always returns 1. You can just add 1 in your if statement. Something like this: if (have_rows(‘candidates’)): $total = 0; while (have_rows(‘candidates’)): the_row(); $position = get_sub_field(‘candidate_position’); if ($position == “Mayor”) { $total++; }; … Read more