How to do a WHILE with condition of a subfield

I’m trying to do a while and display the contents in a 3 columns li.
So far so good, but I want to condition to only apear words that start with letter A, or B, or C.

The problem is that I only managed to create the condition to create the li, and because of this, the code is creating empty fields.
So my question is if there is a way to create this condition in the while.

My code

 <?php if( have_rows('insert_breed_name_to_add') ):
    while( have_rows('insert_breed_name_to_add') **MAYBE INSERT CONDITION HERE? BUT HOW?** ): the_row();
    $count = 1;
    if ($count%3 == 1)
    {?>
     <div class="col-4"><ul>
     <?php } ?>
     <? if( get_sub_field('breed_name')[0] == 'a' OR get_sub_field('breed_name')[0] == 'A'){ ?>
     <li><?php the_sub_field('breed_name'); ?></li>
      <?php }?>
      <?php if ($count%3 == 0){?>
      </ul></div>
      <?php }
      $count++;
      if ($count%3 != 1)?>
      </ul>
      </div>
      <?php endwhile; ?>
      <?php endif; ?>

I’m using wordpress with custom fields, tis one is a repeater

Thanks

Read more here: How to do a WHILE with condition of a subfield

Leave a Reply

Your email address will not be published. Required fields are marked *